Validate Service.Spec.publicIPs to be a valid IP that is not a localhost

This commit is contained in:
Filip Grzadkowski
2015-03-16 15:03:05 +01:00
parent d0b468f4b0
commit 24eb1a08f3
4 changed files with 65 additions and 0 deletions

View File

@@ -222,3 +222,33 @@ func TestIsValidLabelValue(t *testing.T) {
}
}
}
func TestIsValidIP(t *testing.T) {
goodValues := []string{
"1.1.1.1",
"1.1.1.01",
"255.0.0.1",
"1.0.0.0",
"0.0.0.0",
}
for _, val := range goodValues {
if !IsValidIP(val) {
t.Errorf("expected true for %q", val)
}
}
badValues := []string{
"2a00:79e0:2:0:f1c3:e797:93c1:df80", // This is valid IPv6
"a",
"myhost.mydomain",
"-1.0.0.0",
"1.0.0.256",
"1.0.0.1.1",
"1.0.0.1.",
}
for _, val := range badValues {
if IsValidIP(val) {
t.Errorf("expected false for %q", val)
}
}
}