summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/bsdp/bsdp_option_version_test.go
diff options
context:
space:
mode:
authorSean Karlage <skarlage@fb.com>2018-03-21 22:22:21 -0700
committerinsomniac <insomniacslk@users.noreply.github.com>2018-03-22 10:52:25 -0700
commita5034c5a3be9a50b3b222b6234520d005ab41dbb (patch)
tree8625f387b886d1fedfc7628bff1d33928e0fa461 /dhcpv4/bsdp/bsdp_option_version_test.go
parente73a39c9e10a62f7e61949665b2afefc5b094f64 (diff)
Add specific BSDP options
Diffstat (limited to 'dhcpv4/bsdp/bsdp_option_version_test.go')
-rw-r--r--dhcpv4/bsdp/bsdp_option_version_test.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/dhcpv4/bsdp/bsdp_option_version_test.go b/dhcpv4/bsdp/bsdp_option_version_test.go
new file mode 100644
index 0000000..8c09c6a
--- /dev/null
+++ b/dhcpv4/bsdp/bsdp_option_version_test.go
@@ -0,0 +1,44 @@
+// +build darwin
+
+package bsdp
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/require"
+)
+
+func TestOptVersionInterfaceMethods(t *testing.T) {
+ o := OptVersion{Version1_1}
+ require.Equal(t, OptionVersion, o.Code(), "Code")
+ require.Equal(t, 2, o.Length(), "Length")
+ require.Equal(t, []byte{2, 2, 1, 1}, o.ToBytes(), "ToBytes")
+}
+
+func TestParseOptVersion(t *testing.T) {
+ data := []byte{2, 2, 1, 1}
+ o, err := ParseOptVersion(data)
+ require.NoError(t, err)
+ require.Equal(t, &OptVersion{Version1_1}, o)
+
+ // Short byte stream
+ data = []byte{2, 2}
+ _, err = ParseOptVersion(data)
+ require.Error(t, err, "should get error from short byte stream")
+
+ // Wrong code
+ data = []byte{54, 2, 1, 0}
+ _, err = ParseOptVersion(data)
+ require.Error(t, err, "should get error from wrong code")
+
+ // Bad length
+ data = []byte{2, 4, 1, 0}
+ _, err = ParseOptVersion(data)
+ require.Error(t, err, "should get error from bad length")
+}
+
+func TestOptVersionString(t *testing.T) {
+ // known
+ o := OptVersion{Version1_1}
+ require.Equal(t, "BSDP Version -> 1.1", o.String())
+}