summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/option_broadcast_address_test.go
blob: 5b6b44f9cc5e39da059d545d559bb9d4d2eb40a4 (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
package dhcpv4

import (
	"net"
	"testing"

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

func TestOptBroadcastAddressInterfaceMethods(t *testing.T) {
	ip := net.IP{192, 168, 0, 1}
	o := OptBroadcastAddress{BroadcastAddress: ip}

	require.Equal(t, OptionBroadcastAddress, o.Code(), "Code")

	expectedBytes := []byte{192, 168, 0, 1}
	require.Equal(t, expectedBytes, o.ToBytes(), "ToBytes")

	require.Equal(t, "Broadcast Address -> 192.168.0.1", o.String(), "String")
}

func TestParseOptBroadcastAddress(t *testing.T) {
	var (
		o   *OptBroadcastAddress
		err error
	)
	o, err = ParseOptBroadcastAddress([]byte{})
	require.Error(t, err, "empty byte stream")

	o, err = ParseOptBroadcastAddress([]byte{192, 168, 0})
	require.Error(t, err, "wrong IP length")

	o, err = ParseOptBroadcastAddress([]byte{192, 168, 0, 1})
	require.NoError(t, err)
	require.Equal(t, net.IP{192, 168, 0, 1}, o.BroadcastAddress)
}