Make IsValidIP return error strings

Also treat 0.0.0.0 as special, like loopback and multicast.
This commit is contained in:
Tim Hockin
2016-01-04 09:49:39 -08:00
parent 14bece550f
commit 87c1fc50a8
4 changed files with 34 additions and 15 deletions

View File

@@ -293,8 +293,8 @@ func TestIsValidIP(t *testing.T) {
"0.0.0.0",
}
for _, val := range goodValues {
if !IsValidIP(val) {
t.Errorf("expected true for %q", val)
if msgs := IsValidIP(val); len(msgs) != 0 {
t.Errorf("expected true for %q: %v", val, msgs)
}
}
@@ -306,7 +306,7 @@ func TestIsValidIP(t *testing.T) {
"a",
}
for _, val := range badValues {
if IsValidIP(val) {
if msgs := IsValidIP(val); len(msgs) == 0 {
t.Errorf("expected false for %q", val)
}
}