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
|
package dhcpv6
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestParseOptDomainSearchList(t *testing.T) {
data := []byte{
7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 3, 'c', 'o', 'm', 0,
6, 's', 'u', 'b', 'n', 'e', 't', 7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 3, 'o', 'r', 'g', 0,
}
opt, err := ParseOptDomainSearchList(data)
require.NoError(t, err)
require.Equal(t, len(opt.DomainSearchList), 2)
require.Equal(t, opt.DomainSearchList[0], "example.com")
require.Equal(t, opt.DomainSearchList[1], "subnet.example.org")
}
func TestOptDomainSearchListToBytes(t *testing.T) {
expected := []byte{
0, 24, // DOMAIN_SEARCH_LIST
0, 33, // length
7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 3, 'c', 'o', 'm', 0,
6, 's', 'u', 'b', 'n', 'e', 't', 7, 'e', 'x', 'a', 'm', 'p', 'l', 'e', 3, 'o', 'r', 'g', 0,
}
opt := OptDomainSearchList{
DomainSearchList: []string{
"example.com",
"subnet.example.org",
},
}
require.Equal(t, opt.ToBytes(), expected)
}
|