add unit test for GetDNSIP

Signed-off-by: Zhou Hao <zhouhao@cn.fujitsu.com>
pull/6137/head
Zhou Hao 2019-12-20 17:32:50 +08:00
parent 6a5497510a
commit 2167655006
1 changed files with 26 additions and 0 deletions

View File

@ -45,3 +45,29 @@ func TestGetServiceClusterIP(t *testing.T) {
}
}
}
func TestGetDNSIP(t *testing.T) {
testData := []struct {
serviceCIRD string
expectedIP string
err bool
}{
{"1111.0.0.1/12", "", true},
{"10.96.0.0/24", "10.96.0.10", false},
}
for _, tt := range testData {
ip, err := GetDNSIP(tt.serviceCIRD)
if err != nil && !tt.err {
t.Fatalf("GetDNSIP() err = %v", err)
}
if err == nil && tt.err {
t.Fatalf("GetDNSIP() should have returned error, but didn't")
}
if err == nil {
if ip.String() != tt.expectedIP {
t.Fatalf("Expected '%s' but got '%s'", tt.expectedIP, ip.String())
}
}
}
}