Merge pull request #111502 from muyangren2/addtest_apiendpoint

add test for String
This commit is contained in:
Kubernetes Prow Robot 2022-08-01 12:10:40 -07:00 committed by GitHub
commit 3a650c5c56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -50,3 +50,26 @@ func TestAPIEndpointFromString(t *testing.T) {
})
}
}
func TestString(t *testing.T) {
var tests = []struct {
name string
apiEndpoint APIEndpoint
expected string
}{
{name: "ipv4 and port", apiEndpoint: APIEndpoint{AdvertiseAddress: "1.2.3.4", BindPort: 1234}, expected: "1.2.3.4:1234"},
{name: "ipv6 and port", apiEndpoint: APIEndpoint{AdvertiseAddress: "::1", BindPort: 1234}, expected: "[::1]:1234"},
}
for _, rt := range tests {
t.Run(rt.name, func(t *testing.T) {
apiEndpointString := rt.apiEndpoint.String()
if apiEndpointString != rt.expected {
t.Errorf(
"failed String:\n\texpected: %s\n\t actual: %s",
rt.expected,
apiEndpointString,
)
}
})
}
}