Add util to validate namespaced names

This commit is contained in:
Tim Hockin
2014-11-25 00:16:23 -08:00
parent 4845e524af
commit 5ecce5d60c
3 changed files with 58 additions and 13 deletions

View File

@@ -153,3 +153,39 @@ func TestIsValidPortNum(t *testing.T) {
}
}
}
func TestIsQualifiedName(t *testing.T) {
successCases := []string{
"simple",
"now-with-dashes",
"1-starts-with-num",
"1234",
"simple/simple",
"now-with-dashes/simple",
"now-with-dashes/now-with-dashes",
"now.with.dots/simple",
"now-with.dashes-and.dots/simple",
"1-num.2-num/3-num",
"1234/5678",
"1.2.3.4/5678",
}
for i := range successCases {
if !IsQualifiedName(successCases[i]) {
t.Errorf("case[%d] expected success", i)
}
}
errorCases := []string{
"NoUppercase123",
"nospecialchars%^=@",
"cantendwithadash-",
"-cantstartwithadash",
"only/one/slash",
strings.Repeat("a", 254),
}
for i := range errorCases {
if IsQualifiedName(errorCases[i]) {
t.Errorf("case[%d] expected failure", i)
}
}
}