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
42
43
44
45
46
47
48
49
50
|
package dhcpv6
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestOptVendorOpts(t *testing.T) {
optData := []byte("Arista;DCS-7304;01.00;HSH14425148")
// NOTE: this should be aware of endianness
expected := []byte{0xaa, 0xbb, 0xcc, 0xdd}
expected = append(expected, []byte{0, 1, //code
0, byte(len(optData)), //length
}...)
expected = append(expected, optData...)
expectedOpts := OptVendorOpts{}
var vendorOpts []Option
expectedOpts.VendorOpts = append(vendorOpts, &OptionGeneric{OptionCode: 1, OptionData: optData})
var opt OptVendorOpts
err := opt.FromBytes(expected)
require.NoError(t, err)
require.Equal(t, uint32(0xaabbccdd), opt.EnterpriseNumber)
require.Equal(t, expectedOpts.VendorOpts, opt.VendorOpts)
shortData := make([]byte, 1)
var opt2 OptVendorOpts
err = opt2.FromBytes(shortData)
require.Error(t, err)
}
func TestOptVendorOptsToBytes(t *testing.T) {
optData := []byte("Arista;DCS-7304;01.00;HSH14425148")
var opts []Option
opts = append(opts, &OptionGeneric{OptionCode: 1, OptionData: optData})
expected := append([]byte{
0, 0, 0, 0, // EnterpriseNumber
0, 1, // Sub-Option code from vendor
0, byte(len(optData)), // Length of optionData only
}, optData...)
opt := OptVendorOpts{
EnterpriseNumber: 0000,
VendorOpts: opts,
}
toBytes := opt.ToBytes()
require.Equal(t, expected, toBytes)
}
|