mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
netutil: consistently format ipv6 addresses
This formats ipv6 addresses to ensure they can be compared safely Signed-off-by: kidsan <8798449+Kidsan@users.noreply.github.com>
This commit is contained in:
parent
d2fc8dbeeb
commit
c5347cb0c6
@ -103,7 +103,7 @@ func resolveURL(ctx context.Context, lg *zap.Logger, u url.URL) (string, error)
|
||||
)
|
||||
return "", err
|
||||
}
|
||||
if host == "localhost" || net.ParseIP(host) != nil {
|
||||
if host == "localhost" {
|
||||
return "", nil
|
||||
}
|
||||
for ctx.Err() == nil {
|
||||
|
@ -120,13 +120,16 @@ func TestResolveTCPAddrs(t *testing.T) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if tt.hostMap[host] == "" {
|
||||
return nil, errors.New("cannot resolve host")
|
||||
}
|
||||
i, err := strconv.Atoi(port)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if ip := net.ParseIP(host); ip != nil {
|
||||
return &net.TCPAddr{IP: ip, Port: i, Zone: ""}, nil
|
||||
}
|
||||
if tt.hostMap[host] == "" {
|
||||
return nil, errors.New("cannot resolve host")
|
||||
}
|
||||
return &net.TCPAddr{IP: net.ParseIP(tt.hostMap[host]), Port: i, Zone: ""}, nil
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.TODO(), time.Second)
|
||||
@ -152,17 +155,20 @@ func TestURLsEqual(t *testing.T) {
|
||||
"second.com": "10.0.11.2",
|
||||
}
|
||||
resolveTCPAddr = func(ctx context.Context, addr string) (*net.TCPAddr, error) {
|
||||
host, port, herr := net.SplitHostPort(addr)
|
||||
if herr != nil {
|
||||
return nil, herr
|
||||
}
|
||||
if _, ok := hostm[host]; !ok {
|
||||
return nil, errors.New("cannot resolve host.")
|
||||
host, port, err := net.SplitHostPort(addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
i, err := strconv.Atoi(port)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if ip := net.ParseIP(host); ip != nil {
|
||||
return &net.TCPAddr{IP: ip, Port: i, Zone: ""}, nil
|
||||
}
|
||||
if hostm[host] == "" {
|
||||
return nil, errors.New("cannot resolve host")
|
||||
}
|
||||
return &net.TCPAddr{IP: net.ParseIP(hostm[host]), Port: i, Zone: ""}, nil
|
||||
}
|
||||
|
||||
@ -330,6 +336,11 @@ func TestURLStringsEqual(t *testing.T) {
|
||||
"http://host1:8080",
|
||||
"http://host2:8080",
|
||||
}, errOnResolve},
|
||||
{
|
||||
urlsA: []string{"https://[c262:266f:fa53:0ee6:966e:e3f0:d68f:b046]:2380"},
|
||||
urlsB: []string{"https://[c262:266f:fa53:ee6:966e:e3f0:d68f:b046]:2380"},
|
||||
resolver: resolveTCPAddrDefault,
|
||||
},
|
||||
}
|
||||
for idx, c := range cases {
|
||||
t.Logf("TestURLStringsEqual, case #%d", idx)
|
||||
|
Loading…
x
Reference in New Issue
Block a user