format listenning address correctly for IPv6 ip address

This commit is contained in:
ahrtr
2021-12-22 11:07:08 +08:00
parent 9451a41d90
commit 8d8247b092
3 changed files with 50 additions and 1 deletions

View File

@ -129,3 +129,34 @@ func TestUserspaceProxyPriority(t *testing.T) {
t.Errorf("got = %s, want %s", got, want)
}
}
func TestFormatAddr(t *testing.T) {
addrs := []struct {
host string
port uint16
expectedAddr string
}{
{
"192.168.1.10",
2379,
"192.168.1.10:2379",
},
{
"::1",
2379,
"[::1]:2379",
},
{
"2001:db8::ff00:42:8329",
80,
"[2001:db8::ff00:42:8329]:80",
},
}
for _, addr := range addrs {
actualAddr := formatAddr(addr.host, addr.port)
if actualAddr != addr.expectedAddr {
t.Errorf("actualAddr: %s, expectedAddr: %s", actualAddr, addr.expectedAddr)
}
}
}