From 2c40865c227513c8cbaa4453be23888e05657c2b Mon Sep 17 00:00:00 2001 From: Jonathan Lee Date: Wed, 22 Feb 2023 14:55:54 -0800 Subject: [PATCH] Use the IPv6 representation of IPv4 address in unit test --- daemoncfg/daemon_config_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/daemoncfg/daemon_config_test.go b/daemoncfg/daemon_config_test.go index 6d0d916e..a9911cea 100644 --- a/daemoncfg/daemon_config_test.go +++ b/daemoncfg/daemon_config_test.go @@ -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) } @@ -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) }