summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/option_vendorclass_test.go
blob: 0db278fdf8308cf6de7ed227e73cf35c3e4ca701 (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
package dhcpv6

import (
	"testing"

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

func TestParseOptVendorClass(t *testing.T) {
	data := []byte{
		0xaa, 0xbb, 0xcc, 0xdd, // EnterpriseNumber
		0, 10, 'H', 'T', 'T', 'P', 'C', 'l', 'i', 'e', 'n', 't',
		0, 4, 't', 'e', 's', 't',
	}
	opt, err := ParseOptVendorClass(data)
	require.NoError(t, err)
	require.Equal(t, len(opt.Data), 2)
	require.Equal(t, opt.EnterpriseNumber, uint32(0xaabbccdd))
	require.Equal(t, []byte("HTTPClient"), opt.Data[0])
	require.Equal(t, []byte("test"), opt.Data[1])
}

func TestOptVendorClassToBytes(t *testing.T) {
	opt := OptVendorClass{
		EnterpriseNumber: uint32(0xaabbccdd),
		Data: [][]byte{
			[]byte("HTTPClient"),
			[]byte("test"),
		},
	}
	data := opt.ToBytes()
	expected := []byte{
		0, 16, // OptionVendorClass
		0, 22, // length
		0xaa, 0xbb, 0xcc, 0xdd, // EnterpriseNumber
		0, 10, 'H', 'T', 'T', 'P', 'C', 'l', 'i', 'e', 'n', 't',
		0, 4, 't', 'e', 's', 't',
	}
	require.Equal(t, expected, data)
}