diff options
author | Pablo Mazzini <pmazzini@gmail.com> | 2020-03-09 18:18:34 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-09 18:18:34 +0000 |
commit | 27111faab6c0ca7834f2078eb9a14615c8f4fa59 (patch) | |
tree | 2657c611cc944321182aa37db73bc2430b9d402e /dhcpv6/option_dhcpv4_o_dhcpv6_server_test.go | |
parent | 6ddd6be671cd02c85f68cefefb7bbe2500e231d6 (diff) | |
parent | bd34b7c6963c8c124b45759423d41987d428668e (diff) |
Merge branch 'master' into write16
Diffstat (limited to 'dhcpv6/option_dhcpv4_o_dhcpv6_server_test.go')
-rw-r--r-- | dhcpv6/option_dhcpv4_o_dhcpv6_server_test.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/dhcpv6/option_dhcpv4_o_dhcpv6_server_test.go b/dhcpv6/option_dhcpv4_o_dhcpv6_server_test.go new file mode 100644 index 0000000..de86594 --- /dev/null +++ b/dhcpv6/option_dhcpv4_o_dhcpv6_server_test.go @@ -0,0 +1,55 @@ +package dhcpv6 + +import ( + "net" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestParseOptDHCP4oDHCP6Server(t *testing.T) { + data := []byte{ + 0x2a, 0x03, 0x28, 0x80, 0xff, 0xfe, 0x00, 0x0c, 0xfa, 0xce, 0xb0, 0x0c, 0x00, 0x00, 0x00, 0x35, + } + expected := []net.IP{ + net.IP(data), + } + opt, err := ParseOptDHCP4oDHCP6Server(data) + require.NoError(t, err) + require.Equal(t, expected, opt.DHCP4oDHCP6Servers) + require.Equal(t, OptionDHCP4oDHCP6Server, opt.Code()) + require.Contains(t, opt.String(), "4o6-servers=[2a03:2880:fffe:c:face:b00c:0:35]", "String() should contain the correct DHCP4-over-DHCP6 server output") +} + +func TestOptDHCP4oDHCP6ServerToBytes(t *testing.T) { + ip1 := net.ParseIP("2a03:2880:fffe:c:face:b00c:0:35") + ip2 := net.ParseIP("2001:4860:4860::8888") + servers := []net.IP{ip1, ip2} + expected := append([]byte{}, []byte(ip1)...) + expected = append(expected, []byte(ip2)...) + opt := OptDHCP4oDHCP6Server{DHCP4oDHCP6Servers: servers} + require.Equal(t, expected, opt.ToBytes()) +} + +func TestParseOptDHCP4oDHCP6ServerParseNoAddr(t *testing.T) { + data := []byte{ + } + var expected []net.IP + opt, err := ParseOptDHCP4oDHCP6Server(data) + require.NoError(t, err) + require.Equal(t, expected, opt.DHCP4oDHCP6Servers) +} + +func TestOptDHCP4oDHCP6ServerToBytesNoAddr(t *testing.T) { + expected := []byte(nil) + opt := OptDHCP4oDHCP6Server{} + require.Equal(t, expected, opt.ToBytes()) +} + +func TestParseOptDHCP4oDHCP6ServerParseBogus(t *testing.T) { + data := []byte{ + 0x2a, 0x03, 0x28, 0x80, 0xff, 0xfe, 0x00, 0x0c, // invalid IPv6 address + } + _, err := ParseOptDHCP4oDHCP6Server(data) + require.Error(t, err, "An invalid IPv6 address should return an error") +} |