identifiers: use common package for identifier validation
A few days ago, we added validation for namespaces. We've decided to expand these naming rules to include containers. To facilitate this, a common package `identifiers` now provides a common validation area. These rules will be extended to apply to task identifiers, snapshot keys and other areas where user-provided identifiers may be used. Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
@@ -1,79 +0,0 @@
|
||||
package namespaces
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func TestValidNamespaces(t *testing.T) {
|
||||
for _, testcase := range []struct {
|
||||
input string
|
||||
err error
|
||||
}{
|
||||
{
|
||||
input: "default",
|
||||
},
|
||||
{
|
||||
input: "default-default",
|
||||
},
|
||||
{
|
||||
input: "default--default",
|
||||
},
|
||||
{
|
||||
input: "containerd.io",
|
||||
},
|
||||
{
|
||||
input: "foo.boo",
|
||||
},
|
||||
{
|
||||
input: "swarmkit.docker.io",
|
||||
},
|
||||
{
|
||||
input: "zn--e9.org", // or something like it!
|
||||
},
|
||||
{
|
||||
input: ".foo..foo",
|
||||
err: errNamespaceInvalid,
|
||||
},
|
||||
{
|
||||
input: "foo/foo",
|
||||
err: errNamespaceInvalid,
|
||||
},
|
||||
{
|
||||
input: "foo/..",
|
||||
err: errNamespaceInvalid,
|
||||
},
|
||||
{
|
||||
input: "foo..foo",
|
||||
err: errNamespaceInvalid,
|
||||
},
|
||||
{
|
||||
input: "foo.-boo",
|
||||
err: errNamespaceInvalid,
|
||||
},
|
||||
{
|
||||
input: "-foo.boo",
|
||||
err: errNamespaceInvalid,
|
||||
},
|
||||
{
|
||||
input: "foo.boo-",
|
||||
err: errNamespaceInvalid,
|
||||
},
|
||||
{
|
||||
input: "foo_foo.boo_underscores", // boo-urns?
|
||||
err: errNamespaceInvalid,
|
||||
},
|
||||
} {
|
||||
t.Run(testcase.input, func(t *testing.T) {
|
||||
if err := Validate(testcase.input); errors.Cause(err) != testcase.err {
|
||||
t.Log(errors.Cause(err), testcase.err)
|
||||
if testcase.err == nil {
|
||||
t.Fatalf("unexpected error: %v != nil", err)
|
||||
} else {
|
||||
t.Fatalf("expected error %v to be %v", err, testcase.err)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user