summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/option_domainsearchlist_test.go
diff options
context:
space:
mode:
authorinsomniac <insomniacslk@users.noreply.github.com>2018-05-12 02:08:20 +0100
committerGitHub <noreply@github.com>2018-05-12 02:08:20 +0100
commit5e40d13e338c363f111c326987b14023db25c40d (patch)
tree3de3f34d8cbf647a6303b2d923fb4c22627c810c /dhcpv6/option_domainsearchlist_test.go
parentd7cd0594274352de80d86a3bf32b487dfde63629 (diff)
OptDomainSearchList: made fields public and added unit tests (#64)
Diffstat (limited to 'dhcpv6/option_domainsearchlist_test.go')
-rw-r--r--dhcpv6/option_domainsearchlist_test.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/dhcpv6/option_domainsearchlist_test.go b/dhcpv6/option_domainsearchlist_test.go
new file mode 100644
index 0000000..d5b8bf7
--- /dev/null
+++ b/dhcpv6/option_domainsearchlist_test.go
@@ -0,0 +1,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)
+}