test: add IPv6 unit test

This commit is contained in:
andyzhangx 2022-05-15 06:58:34 +00:00
parent dcd24e51e6
commit ba1b9dd8d4

View File

@ -211,3 +211,39 @@ func getWorkDirPath(dir string) (string, error) {
} }
return fmt.Sprintf("%s%c%s", path, os.PathSeparator, dir), nil return fmt.Sprintf("%s%c%s", path, os.PathSeparator, dir), nil
} }
func TestGetServerFromSource(t *testing.T) {
tests := []struct {
desc string
server string
result string
}{
{
desc: "ipv4",
server: "10.127.0.1",
result: "10.127.0.1",
},
{
desc: "ipv6",
server: "0:0:0:0:0:0:0:1",
result: "[0:0:0:0:0:0:0:1]",
},
{
desc: "ipv6 with brackets",
server: "[0:0:0:0:0:0:0:2]",
result: "[0:0:0:0:0:0:0:2]",
},
{
desc: "other fqdn",
server: "bing.com",
result: "bing.com",
},
}
for _, test := range tests {
result := getServerFromSource(test.server)
if result != test.result {
t.Errorf("Unexpected result: %s, expected: %s", result, test.result)
}
}
}