mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
graph: validate tags properly & add unit tests
Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
This commit is contained in:
parent
88a786d3c4
commit
ada883b198
2 changed files with 19 additions and 1 deletions
|
@ -19,7 +19,7 @@ import (
|
|||
const DEFAULTTAG = "latest"
|
||||
|
||||
var (
|
||||
validTagName = regexp.MustCompile(`^[\w][\w.-]{1,29}$`)
|
||||
validTagName = regexp.MustCompile(`^[\w][\w.-]{0,29}$`)
|
||||
)
|
||||
|
||||
type TagStore struct {
|
||||
|
|
|
@ -114,3 +114,21 @@ func TestLookupImage(t *testing.T) {
|
|||
t.Errorf("Expected 1 image, none found")
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidTagName(t *testing.T) {
|
||||
validTags := []string{"9", "foo", "foo-test", "bar.baz.boo"}
|
||||
for _, tag := range validTags {
|
||||
if err := validateTagName(tag); err != nil {
|
||||
t.Errorf("'%s' should've been a valid tag", tag)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestInvalidTagName(t *testing.T) {
|
||||
validTags := []string{"-9", ".foo", "-test", ".", "-"}
|
||||
for _, tag := range validTags {
|
||||
if err := validateTagName(tag); err == nil {
|
||||
t.Errorf("'%s' shouldn't have been a valid tag", tag)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue