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

import (
	"testing"

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

func TestOptMaximumDHCPMessageSize(t *testing.T) {
	o := OptMaxMessageSize(1500)
	require.Equal(t, OptionMaximumDHCPMessageSize, o.Code, "Code")
	require.Equal(t, []byte{5, 220}, o.Value.ToBytes(), "ToBytes")
	require.Equal(t, "Maximum DHCP Message Size: 1500", o.String())
}

func TestGetMaximumDHCPMessageSize(t *testing.T) {
	m, _ := New(WithGeneric(OptionMaximumDHCPMessageSize, []byte{5, 220}))
	o, err := m.MaxMessageSize()
	require.NoError(t, err)
	require.Equal(t, uint16(1500), o)

	// Short byte stream
	m, _ = New(WithGeneric(OptionMaximumDHCPMessageSize, []byte{2}))
	_, err = m.MaxMessageSize()
	require.Error(t, err, "should get error from short byte stream")

	// Bad length
	m, _ = New(WithGeneric(OptionMaximumDHCPMessageSize, []byte{2, 2, 2}))
	_, err = m.MaxMessageSize()
	require.Error(t, err, "should get error from bad length")
}