add test for String

modify
This commit is contained in:
muyangren2 2022-07-28 16:16:05 +08:00
parent a4a22a2562
commit 2422e99df3

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,
)
}
})
}
}