forked from elastic/package-storage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Validation of package (elastic#97)
To make sure the registry only serves valid packages, packages should be validated during build time. For this a `Package.Validate() error` method was added. For not it is simple and only checks for title and description but more checks should be added in the future. The packages which were not valid were updated.
- Loading branch information
Showing
8 changed files
with
76 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package util | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var ( | ||
title = "foo" | ||
) | ||
var packageTests = []struct { | ||
p Package | ||
valid bool | ||
description string | ||
}{ | ||
{ | ||
Package{}, | ||
false, | ||
"empty", | ||
}, | ||
{ | ||
Package{ | ||
Title: &title, | ||
}, | ||
false, | ||
"missing description", | ||
}, | ||
{ | ||
Package{ | ||
Title: &title, | ||
Description: "my description", | ||
}, | ||
true, | ||
"complete", | ||
}, | ||
} | ||
|
||
func TestValidate(t *testing.T) { | ||
for _, tt := range packageTests { | ||
t.Run(tt.description, func(t *testing.T) { | ||
err := tt.p.Validate() | ||
|
||
if err != nil { | ||
assert.False(t, tt.valid) | ||
} else { | ||
assert.True(t, tt.valid) | ||
} | ||
}) | ||
} | ||
} |