summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/option_subnet_mask_test.go
blob: beeeda009fea0cf604547d6c39b15dff5b2361ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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{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{255})
	require.Error(t, err, "short byte stream")

	o, err = ParseOptSubnetMask([]byte{255, 255, 255, 0})
	require.NoError(t, err)
	require.Equal(t, net.IPMask{255, 255, 255, 0}, o.SubnetMask)
}