diff options
author | David Barr <38654497+davebarrau@users.noreply.github.com> | 2018-10-12 11:09:04 +1100 |
---|---|---|
committer | insomniac <insomniacslk@users.noreply.github.com> | 2018-10-11 17:09:04 -0700 |
commit | dc01165c86340093eacf62c0856ae4e2164a4845 (patch) | |
tree | 9ca76ae4103c3e63cd86620fdec230e5cfe5b78d /dhcpv6/option_nii_test.go | |
parent | ee671d361777cc640550bab38cc6b0d412396f80 (diff) |
Add some more DHCPv6 option tests. (#171)
* Add some more DHCPv6 option tests.
* Remove AddRequestedOption() duplicate detection test due to failing on Go 1.9
Diffstat (limited to 'dhcpv6/option_nii_test.go')
-rw-r--r-- | dhcpv6/option_nii_test.go | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/dhcpv6/option_nii_test.go b/dhcpv6/option_nii_test.go new file mode 100644 index 0000000..190c0e3 --- /dev/null +++ b/dhcpv6/option_nii_test.go @@ -0,0 +1,70 @@ +package dhcpv6 + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestOptNetworkInterfaceIdParse(t *testing.T) { + expected := []byte{ + 1, // type (UNDI) + 3, // major revision + 20, // minor revision + } + opt, err := ParseOptNetworkInterfaceId(expected) + require.NoError(t, err, "ParseOptNetworkInterfaceId() should not return an error with correct bytes") + require.Equal(t, 3, opt.Length(), "Length() should return 3") + require.Equal(t, OptionNII, opt.Code(), OptionNII, "Code() should return 62 for OptNetworkInterfaceId") + require.Equal(t, uint8(1), opt.Type(), "Type() should return 1 for UNDI") + require.Equal(t, uint8(3), opt.Major(), "Major() should return 1 for UNDI") + require.Equal(t, uint8(20), opt.Minor(), "Minor() should return 1 for UNDI") +} + +func TestOptNetworkInterfaceIdToBytes(t *testing.T) { + expected := []byte{ + 0, 62, // OptNetworkInterfaceId + 0, 3, // length + 1, // type (UNDI) + 3, // major revision + 20, // minor revision + } + opt := OptNetworkInterfaceId{} + opt.SetType(1) + opt.SetMajor(3) + opt.SetMinor(20) + require.Equal(t, expected, opt.ToBytes()) +} + +func TestOptNetworkInterfaceIdTooShort(t *testing.T) { + buf := []byte{ + 0, 62, // OptNetworkInterfaceId + 0, 3, // length + 1, // type (UNDI) + // missing major/minor revision bytes + } + _, err := ParseOptNetworkInterfaceId(buf) + require.Error(t, err, "ParseOptNetworkInterfaceId() should return an error on truncated options") +} + +func TestOptNetworkInterfaceIdString(t *testing.T) { + buf := []byte{ + 1, // type (UNDI) + 3, // major revision + 20, // minor revision + } + opt, err := ParseOptNetworkInterfaceId(buf) + require.NoError(t, err) + require.Contains( + t, + opt.String(), + "type=First gen. PXE boot ROMs, revision=3.20", + "String() should contain the type and revision", + ) + opt.SetType(200) + require.Contains( + t, opt.String(), + "type=Unknown", + "String() should contain unknown for an unknown type", + ) +} |