summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/option_nii_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'dhcpv6/option_nii_test.go')
-rw-r--r--dhcpv6/option_nii_test.go70
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",
+ )
+}