distribution/common/names_test.go
Stephen J Day 375f3cc136 Define common regexps used across registry application
This commit adds regular expression definitions for several string identifiers
used througout the registry. The repository name regex supports up to five path
path components and restricts repeated periods, dashes and underscores. The tag
regex simply validates the length of the tag and that printable characters are
required.

Though we define a new package common, these definition should land in docker
core.
2014-11-12 16:53:55 -08:00

62 lines
947 B
Go

package common
import (
"testing"
)
func TestRepositoryNameRegexp(t *testing.T) {
for _, testcase := range []struct {
input string
valid bool
}{
{
input: "simple/name",
valid: true,
},
{
input: "library/ubuntu",
valid: true,
},
{
input: "docker/stevvooe/app",
valid: true,
},
{
input: "aa/aa/aa/aa/aa/aa/aa/aa/aa/bb/bb/bb/bb/bb/bb",
valid: true,
},
{
input: "a/a/a/a/a/a/b/b/b/b",
valid: false,
},
{
input: "a/a/a/a/",
valid: false,
},
{
input: "foo.com/bar/baz",
valid: true,
},
{
input: "blog.foo.com/bar/baz",
valid: true,
},
{
input: "asdf",
valid: false,
},
{
input: "asdf$$^/",
valid: false,
},
} {
if RepositoryNameRegexp.MatchString(testcase.input) != testcase.valid {
status := "invalid"
if testcase.valid {
status = "valid"
}
t.Fatalf("expected %q to be %s repository name", testcase.input, status)
}
}
}