summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/option_clientlinklayeraddress_test.go
blob: 1ef40c52d586b05b69baff129b6894c226743236 (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
39
40
41
package dhcpv6

import (
	"bytes"
	"net"
	"testing"

	"github.com/insomniacslk/dhcp/iana"
	"github.com/stretchr/testify/require"
)

func TestParseOptClientLinkLayerAddress(t *testing.T) {
	data := []byte{
		0, 1, // LinkLayerType
		164, 131, 231, 227, 223, 136,
	}
	var opt optClientLinkLayerAddress
	err := opt.FromBytes(data)

	require.NoError(t, err)
	require.Equal(t, OptionClientLinkLayerAddr, opt.Code())
	require.Equal(t, iana.HWTypeEthernet, opt.LinkLayerType)
	require.Equal(t, net.HardwareAddr(data[2:]), opt.LinkLayerAddress)
	require.Equal(t, "Client Link-Layer Address: Type=Ethernet LinkLayerAddress=a4:83:e7:e3:df:88", opt.String())
}

func TestOptClientLinkLayerAddressToBytes(t *testing.T) {
	mac, _ := net.ParseMAC("a4:83:e7:e3:df:88")
	opt := optClientLinkLayerAddress{
		LinkLayerType:    iana.HWTypeEthernet,
		LinkLayerAddress: mac,
	}
	want := []byte{
		0, 1, // LinkLayerType
		164, 131, 231, 227, 223, 136,
	}
	b := opt.ToBytes()
	if !bytes.Equal(b, want) {
		t.Fatalf("opt.ToBytes()=%v, want %v", b, want)
	}
}