summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/option_server_identifier_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'dhcpv4/option_server_identifier_test.go')
-rw-r--r--dhcpv4/option_server_identifier_test.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/dhcpv4/option_server_identifier_test.go b/dhcpv4/option_server_identifier_test.go
new file mode 100644
index 0000000..94fb542
--- /dev/null
+++ b/dhcpv4/option_server_identifier_test.go
@@ -0,0 +1,44 @@
+package dhcpv4
+
+import (
+ "net"
+ "testing"
+
+ "github.com/stretchr/testify/require"
+)
+
+func TestOptRequestedIPAddressInterfaceMethods(t *testing.T) {
+ ip := net.IP{192, 168, 0, 1}
+ o := OptRequestedIPAddress{RequestedAddr: ip}
+
+ require.Equal(t, OptionRequestedIPAddress, o.Code(), "Code")
+
+ expectedBytes := []byte{50, 4, 192, 168, 0, 1}
+ require.Equal(t, expectedBytes, o.ToBytes(), "ToBytes")
+
+ require.Equal(t, 4, o.Length(), "Length")
+
+ require.Equal(t, "Requested IP Address -> 192.168.0.1", o.String(), "String")
+}
+
+func TestParseOptRequestedIPAddress(t *testing.T) {
+ var (
+ o *OptRequestedIPAddress
+ err error
+ )
+ o, err = ParseOptRequestedIPAddress([]byte{})
+ require.Error(t, err, "empty byte stream")
+
+ o, err = ParseOptRequestedIPAddress([]byte{50, 4, 192})
+ require.Error(t, err, "short byte stream")
+
+ o, err = ParseOptRequestedIPAddress([]byte{50, 3, 192, 168, 0, 1})
+ require.Error(t, err, "wrong IP length")
+
+ o, err = ParseOptRequestedIPAddress([]byte{53, 4, 192, 168, 1})
+ require.Error(t, err, "wrong option code")
+
+ o, err = ParseOptRequestedIPAddress([]byte{50, 4, 192, 168, 0, 1})
+ require.NoError(t, err)
+ require.Equal(t, net.IP{192, 168, 0, 1}, o.RequestedAddr)
+}