summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/option_maximum_dhcp_message_size_test.go
blob: 0b36b0e6b111da5022195779bb73a55110ab1a12 (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
package dhcpv4

import (
	"testing"

	"github.com/stretchr/testify/require"
)

func TestOptMaximumDHCPMessageSizeInterfaceMethods(t *testing.T) {
	o := OptMaximumDHCPMessageSize{Size: 1500}
	require.Equal(t, OptionMaximumDHCPMessageSize, o.Code(), "Code")
	require.Equal(t, []byte{5, 220}, o.ToBytes(), "ToBytes")
}

func TestParseOptMaximumDHCPMessageSize(t *testing.T) {
	data := []byte{5, 220}
	o, err := ParseOptMaximumDHCPMessageSize(data)
	require.NoError(t, err)
	require.Equal(t, &OptMaximumDHCPMessageSize{Size: 1500}, o)

	// Short byte stream
	data = []byte{2}
	_, err = ParseOptMaximumDHCPMessageSize(data)
	require.Error(t, err, "should get error from short byte stream")

	// Bad length
	data = []byte{1, 1, 1}
	_, err = ParseOptMaximumDHCPMessageSize(data)
	require.Error(t, err, "should get error from bad length")
}

func TestOptMaximumDHCPMessageSizeString(t *testing.T) {
	o := OptMaximumDHCPMessageSize{Size: 1500}
	require.Equal(t, "Maximum DHCP Message Size -> 1500", o.String())
}