summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/bsdp/bsdp_option_generic_test.go
diff options
context:
space:
mode:
authorSean Karlage <skarlage@get9.io>2018-03-26 15:40:59 -0700
committerinsomniac <insomniacslk@users.noreply.github.com>2018-03-26 15:40:59 -0700
commitbb95a0335e44a76a1e061b5dea2b1592c55177ac (patch)
treefa3dc814cbfe44182c151b9bd2646212be2b2e91 /dhcpv4/bsdp/bsdp_option_generic_test.go
parente920c892c48b14dcb1e50e247836b2b9a69fa929 (diff)
Add some more specific bsdp options + vendor specific implementation (#21)
Add some more specific options + vendor specific implementation
Diffstat (limited to 'dhcpv4/bsdp/bsdp_option_generic_test.go')
-rw-r--r--dhcpv4/bsdp/bsdp_option_generic_test.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/dhcpv4/bsdp/bsdp_option_generic_test.go b/dhcpv4/bsdp/bsdp_option_generic_test.go
new file mode 100644
index 0000000..5a5ad25
--- /dev/null
+++ b/dhcpv4/bsdp/bsdp_option_generic_test.go
@@ -0,0 +1,66 @@
+// +build darwin
+
+package bsdp
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/require"
+)
+
+func TestParseOptGeneric(t *testing.T) {
+ // Empty bytestream produces error
+ _, err := ParseOptGeneric([]byte{})
+ require.Error(t, err, "error from empty bytestream")
+}
+
+func TestOptGenericCode(t *testing.T) {
+ o := OptGeneric{
+ OptionCode: OptionMessageType,
+ Data: []byte{byte(MessageTypeList)},
+ }
+ require.Equal(t, OptionMessageType, o.Code())
+}
+
+func TestOptGenericData(t *testing.T) {
+ o := OptGeneric{
+ OptionCode: OptionServerIdentifier,
+ Data: []byte{192, 168, 0, 1},
+ }
+ require.Equal(t, []byte{192, 168, 0, 1}, o.Data)
+}
+
+func TestOptGenericToBytes(t *testing.T) {
+ o := OptGeneric{
+ OptionCode: OptionServerIdentifier,
+ Data: []byte{192, 168, 0, 1},
+ }
+ serialized := o.ToBytes()
+ expected := []byte{3, 4, 192, 168, 0, 1}
+ require.Equal(t, expected, serialized)
+}
+
+func TestOptGenericString(t *testing.T) {
+ o := OptGeneric{
+ OptionCode: OptionServerIdentifier,
+ Data: []byte{192, 168, 0, 1},
+ }
+ require.Equal(t, "BSDP Server Identifier -> [192 168 0 1]", o.String())
+}
+
+func TestOptGenericStringUnknown(t *testing.T) {
+ o := OptGeneric{
+ OptionCode: 102, // Returend option code.
+ Data: []byte{5},
+ }
+ require.Equal(t, "Unknown -> [5]", o.String())
+}
+
+func TestOptGenericLength(t *testing.T) {
+ filename := "some_machine_name"
+ o := OptGeneric{
+ OptionCode: OptionMachineName,
+ Data: []byte(filename),
+ }
+ require.Equal(t, len(filename), o.Length())
+}