namespaces: ensure that tests actually fail

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day 2017-06-22 16:05:48 -07:00
parent c4da4ed393
commit c6efdfb9ee
No known key found for this signature in database
GPG Key ID: 67B3DED84EDC823F

View File

@ -8,89 +8,71 @@ import (
func TestValidNamespaces(t *testing.T) { func TestValidNamespaces(t *testing.T) {
for _, testcase := range []struct { for _, testcase := range []struct {
name string
input string input string
err error err error
}{ }{
{ {
name: "Default",
input: "default", input: "default",
}, },
{ {
name: "Hyphen",
input: "default-default", input: "default-default",
}, },
{ {
name: "DoubleHyphen",
input: "default--default", input: "default--default",
}, },
{ {
name: "containerD",
input: "containerd.io", input: "containerd.io",
}, },
{ {
name: "SwarmKit", input: "foo.boo",
},
{
input: "swarmkit.docker.io", input: "swarmkit.docker.io",
}, },
{ {
name: "Punycode",
input: "zn--e9.org", // or something like it! input: "zn--e9.org", // or something like it!
}, },
{ {
name: "LeadingPeriod",
input: ".foo..foo", input: ".foo..foo",
err: errNamespaceInvalid, err: errNamespaceInvalid,
}, },
{ {
name: "Path",
input: "foo/foo", input: "foo/foo",
err: errNamespaceInvalid, err: errNamespaceInvalid,
}, },
{ {
name: "ParentDir",
input: "foo/..", input: "foo/..",
err: errNamespaceInvalid, err: errNamespaceInvalid,
}, },
{ {
name: "RepeatedPeriod",
input: "foo..foo", input: "foo..foo",
err: errNamespaceInvalid, err: errNamespaceInvalid,
}, },
{ {
name: "OutOfPlaceHyphenEmbedded",
input: "foo.-boo", input: "foo.-boo",
err: errNamespaceInvalid, err: errNamespaceInvalid,
}, },
{ {
name: "OutOfPlaceHyphen",
input: "-foo.boo", input: "-foo.boo",
err: errNamespaceInvalid, err: errNamespaceInvalid,
}, },
{ {
name: "OutOfPlaceHyphenEnd", input: "foo.boo-",
input: "foo.boo",
err: errNamespaceInvalid, err: errNamespaceInvalid,
}, },
{ {
name: "Underscores",
input: "foo_foo.boo_underscores", // boo-urns? input: "foo_foo.boo_underscores", // boo-urns?
err: errNamespaceInvalid, err: errNamespaceInvalid,
}, },
} { } {
t.Run(testcase.name, func(t *testing.T) { t.Run(testcase.input, func(t *testing.T) {
if err := Validate(testcase.input); err != nil { if err := Validate(testcase.input); errors.Cause(err) != testcase.err {
if errors.Cause(err) != testcase.err { t.Log(errors.Cause(err), testcase.err)
if testcase.err == nil { if testcase.err == nil {
t.Fatalf("unexpected error: %v != nil", err) t.Fatalf("unexpected error: %v != nil", err)
} else { } else {
t.Fatalf("expected error %v to be %v", err, testcase.err) t.Fatalf("expected error %v to be %v", err, testcase.err)
} }
} else {
t.Logf("invalid %q detected as invalid: %v", testcase.input, err)
return
}
t.Logf("%q is a valid namespace", testcase.input)
} }
}) })
} }