2015-01-06 00:44:03 +00:00
|
|
|
package v2
|
2014-11-13 00:39:35 +00:00
|
|
|
|
|
|
|
import (
|
2015-07-10 18:00:06 +00:00
|
|
|
"strconv"
|
2015-03-05 15:11:37 +00:00
|
|
|
"strings"
|
2014-11-13 00:39:35 +00:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestRepositoryNameRegexp(t *testing.T) {
|
|
|
|
for _, testcase := range []struct {
|
|
|
|
input string
|
2014-11-17 19:28:32 +00:00
|
|
|
err error
|
2014-11-13 00:39:35 +00:00
|
|
|
}{
|
2015-07-10 18:00:06 +00:00
|
|
|
{
|
|
|
|
input: "",
|
|
|
|
err: ErrRepositoryNameEmpty,
|
|
|
|
},
|
2015-01-28 22:51:02 +00:00
|
|
|
{
|
|
|
|
input: "short",
|
|
|
|
},
|
2014-11-13 00:39:35 +00:00
|
|
|
{
|
|
|
|
input: "simple/name",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "library/ubuntu",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "docker/stevvooe/app",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "aa/aa/aa/aa/aa/aa/aa/aa/aa/bb/bb/bb/bb/bb/bb",
|
|
|
|
},
|
|
|
|
{
|
2014-11-17 19:28:32 +00:00
|
|
|
input: "aa/aa/bb/bb/bb",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "a/a/a/b/b",
|
2014-11-13 00:39:35 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "a/a/a/a/",
|
2015-07-10 18:00:06 +00:00
|
|
|
err: ErrRepositoryNameComponentInvalid,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "a//a/a",
|
|
|
|
err: ErrRepositoryNameComponentInvalid,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "a",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "a/aa",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "aa/a",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "a/aa/a",
|
2014-11-13 00:39:35 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "foo.com/bar/baz",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "blog.foo.com/bar/baz",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "asdf",
|
2014-11-17 19:28:32 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "asdf$$^/aa",
|
|
|
|
err: ErrRepositoryNameComponentInvalid,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "aa-a/aa",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "aa/aa",
|
2014-11-13 00:39:35 +00:00
|
|
|
},
|
|
|
|
{
|
2014-11-17 19:28:32 +00:00
|
|
|
input: "a-a/a-a",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "a-/a/a/a",
|
|
|
|
err: ErrRepositoryNameComponentInvalid,
|
2014-11-13 00:39:35 +00:00
|
|
|
},
|
2015-03-05 15:11:37 +00:00
|
|
|
{
|
|
|
|
input: strings.Repeat("a", 255),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: strings.Repeat("a", 256),
|
|
|
|
err: ErrRepositoryNameLong,
|
|
|
|
},
|
2015-06-04 23:12:35 +00:00
|
|
|
{
|
|
|
|
input: "-foo/bar",
|
|
|
|
err: ErrRepositoryNameComponentInvalid,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "foo/bar-",
|
|
|
|
err: ErrRepositoryNameComponentInvalid,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "foo-/bar",
|
|
|
|
err: ErrRepositoryNameComponentInvalid,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "foo/-bar",
|
|
|
|
err: ErrRepositoryNameComponentInvalid,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "_foo/bar",
|
|
|
|
err: ErrRepositoryNameComponentInvalid,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "foo/bar_",
|
|
|
|
err: ErrRepositoryNameComponentInvalid,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "____/____",
|
|
|
|
err: ErrRepositoryNameComponentInvalid,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "_docker/_docker",
|
|
|
|
err: ErrRepositoryNameComponentInvalid,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
input: "docker_/docker_",
|
|
|
|
err: ErrRepositoryNameComponentInvalid,
|
|
|
|
},
|
2014-11-13 00:39:35 +00:00
|
|
|
} {
|
2014-11-17 19:28:32 +00:00
|
|
|
failf := func(format string, v ...interface{}) {
|
2015-07-10 18:00:06 +00:00
|
|
|
t.Logf(strconv.Quote(testcase.input)+": "+format, v...)
|
2014-11-17 19:28:32 +00:00
|
|
|
t.Fail()
|
|
|
|
}
|
|
|
|
|
2015-05-19 17:25:08 +00:00
|
|
|
if err := ValidateRepositoryName(testcase.input); err != testcase.err {
|
2014-11-17 19:28:32 +00:00
|
|
|
if testcase.err != nil {
|
|
|
|
if err != nil {
|
|
|
|
failf("unexpected error for invalid repository: got %v, expected %v", err, testcase.err)
|
|
|
|
} else {
|
|
|
|
failf("expected invalid repository: %v", testcase.err)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if err != nil {
|
|
|
|
// Wrong error returned.
|
|
|
|
failf("unexpected error validating repository name: %v, expected %v", err, testcase.err)
|
|
|
|
} else {
|
|
|
|
failf("unexpected error validating repository name: %v", err)
|
|
|
|
}
|
|
|
|
}
|
2014-11-13 00:39:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|