Add dns-952-identifier validation to service ids.

This commit is contained in:
Brendan Burns
2014-08-03 21:02:10 -07:00
parent 07bef429b1
commit 20a8f03d62
4 changed files with 37 additions and 1 deletions

View File

@@ -100,6 +100,7 @@ func TestIsCIdentifier(t *testing.T) {
"-", "a-", "-a", "1-", "-1", "1_", "1_2",
".", "a.", ".a", "a.b", "1.", ".1", "1.2",
" ", "a ", " a", "a b", "1 ", " 1", "1 2",
"#a#",
}
for _, val := range badValues {
if IsCIdentifier(val) {
@@ -123,3 +124,26 @@ func TestIsValidPortNum(t *testing.T) {
}
}
}
func TestIsDNS952(t *testing.T) {
goodValues := []string{
"a", "ab", "abc", "a1", "a-b", "a-1", "a-1-2-b", "abc-123",
}
for _, val := range goodValues {
if !IsDNS952Label(val) {
t.Errorf("expected true for '%s'", val)
}
}
badValues := []string{
"", "1", "123", "1a",
"-", "a-", "-a", "1-", "-1", "1-2",
" ", "a ", " a", "a b", "1 ", " 1", "1 2",
"A", "AB", "AbC", "A1", "A-B", "A-1", "A-1-2-B",
}
for _, val := range badValues {
if IsDNS952Label(val) {
t.Errorf("expected false for '%s'", val)
}
}
}