Skip to content

Commit

Permalink
Use the IPv6 representation of IPv4 address in unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
jj22ee committed Feb 22, 2023
1 parent b178189 commit 2c40865
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions daemoncfg/daemon_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,14 @@ func TestGetDaemonEndpointsForHostname1(t *testing.T) { // parsing hostname - si
tcpEndpt, _ := resolveTCPAddr(tcpAddr)
dEndpt, _ := GetDaemonEndpointsFromString("localhost:2000")

// Keep dEndpt.UDPAddr.IP as the IPv6 representation of an IPv4 address
if (len(dEndpt.UDPAddr.IP) == 4) {
dEndpt.UDPAddr.IP = dEndpt.UDPAddr.IP.To16()
}
if (len(dEndpt.TCPAddr.IP) == 4) {
dEndpt.TCPAddr.IP = dEndpt.TCPAddr.IP.To16()
}

assert.Equal(t, dEndpt.UDPAddr, udpEndpt)
assert.Equal(t, dEndpt.TCPAddr, tcpEndpt)
}
Expand All @@ -259,6 +267,14 @@ func TestGetDaemonEndpointsForHostname3(t *testing.T) { // parsing hostname - do
tcpEndpt, _ := resolveTCPAddr(tcpAddr)
dEndpt, _ := GetDaemonEndpointsFromString("tcp:localhost:2000 udp:localhost:2000")

// Keep dEndpt.UDPAddr.IP as the IPv6 representation of an IPv4 address
if (len(dEndpt.UDPAddr.IP) == 4) {
dEndpt.UDPAddr.IP = dEndpt.UDPAddr.IP.To16()
}
if (len(dEndpt.TCPAddr.IP) == 4) {
dEndpt.TCPAddr.IP = dEndpt.TCPAddr.IP.To16()
}

assert.Equal(t, dEndpt.UDPAddr, udpEndpt)
assert.Equal(t, dEndpt.TCPAddr, tcpEndpt)
}
Expand Down

0 comments on commit 2c40865

Please sign in to comment.