diff options
author | Sean Karlage <skarlage@get9.io> | 2018-07-29 13:51:36 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-29 13:51:36 -0500 |
commit | 23c03c8fa262c77c68741b079e0e1d2c91397823 (patch) | |
tree | 77d43444c3369acd69c6ead9bd353a7b00bba987 /dhcpv4/option_subnet_mask_test.go | |
parent | b30145cf5536cc1a134ad83cfce21f0b7249cf84 (diff) | |
parent | 377731752ec3ddf7162413ad5e5ef8620e0b3857 (diff) |
Merge pull request #101 from pmazzini/master
add OptSubnetMask
Diffstat (limited to 'dhcpv4/option_subnet_mask_test.go')
-rw-r--r-- | dhcpv4/option_subnet_mask_test.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/dhcpv4/option_subnet_mask_test.go b/dhcpv4/option_subnet_mask_test.go new file mode 100644 index 0000000..4cb8819 --- /dev/null +++ b/dhcpv4/option_subnet_mask_test.go @@ -0,0 +1,44 @@ +package dhcpv4 + +import ( + "net" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestOptSubnetMaskInterfaceMethods(t *testing.T) { + mask := net.IPMask{255, 255, 255, 0} + o := OptSubnetMask{SubnetMask: mask} + + require.Equal(t, OptionSubnetMask, o.Code(), "Code") + + expectedBytes := []byte{1, 4, 255, 255, 255, 0} + require.Equal(t, expectedBytes, o.ToBytes(), "ToBytes") + + require.Equal(t, 4, o.Length(), "Length") + + require.Equal(t, "Subnet Mask -> ffffff00", o.String(), "String") +} + +func TestParseOptSubnetMask(t *testing.T) { + var ( + o *OptSubnetMask + err error + ) + o, err = ParseOptSubnetMask([]byte{}) + require.Error(t, err, "empty byte stream") + + o, err = ParseOptSubnetMask([]byte{1, 4, 255}) + require.Error(t, err, "short byte stream") + + o, err = ParseOptSubnetMask([]byte{1, 3, 255, 255, 255, 0}) + require.Error(t, err, "wrong IP length") + + o, err = ParseOptSubnetMask([]byte{2, 4, 255, 255, 255}) + require.Error(t, err, "wrong option code") + + o, err = ParseOptSubnetMask([]byte{1, 4, 255, 255, 255, 0}) + require.NoError(t, err) + require.Equal(t, net.IPMask{255, 255, 255, 0}, o.SubnetMask) +} |