summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/option_ip_address_lease_time_test.go
diff options
context:
space:
mode:
authorSean Karlage <skarlage@get9.io>2018-07-30 08:46:36 -0700
committerGitHub <noreply@github.com>2018-07-30 08:46:36 -0700
commit6cf562816e82894ad1b0eb86923b5bcb7b7d2962 (patch)
treec81a97c8b540ea830615e39eaae1fde420eb9e46 /dhcpv4/option_ip_address_lease_time_test.go
parentb1289a39b521aa6ce714af91bab9f8104e5cc002 (diff)
parentb64f581df56ab8050636c58d5096b6b499725807 (diff)
Merge pull request #108 from pmazzini/master
add OptIPAddressLeaseTime
Diffstat (limited to 'dhcpv4/option_ip_address_lease_time_test.go')
-rw-r--r--dhcpv4/option_ip_address_lease_time_test.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/dhcpv4/option_ip_address_lease_time_test.go b/dhcpv4/option_ip_address_lease_time_test.go
new file mode 100644
index 0000000..66715bd
--- /dev/null
+++ b/dhcpv4/option_ip_address_lease_time_test.go
@@ -0,0 +1,41 @@
+package dhcpv4
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/require"
+)
+
+func TestOptIPAddressLeaseTimeInterfaceMethods(t *testing.T) {
+ o := OptIPAddressLeaseTime{LeaseTime: 43200}
+ require.Equal(t, OptionIPAddressLeaseTime, o.Code(), "Code")
+ require.Equal(t, 4, o.Length(), "Length")
+ require.Equal(t, []byte{51, 4, 0, 0, 168, 192}, o.ToBytes(), "ToBytes")
+}
+
+func TestParseOptIPAddressLeaseTime(t *testing.T) {
+ data := []byte{51, 4, 0, 0, 168, 192}
+ o, err := ParseOptIPAddressLeaseTime(data)
+ require.NoError(t, err)
+ require.Equal(t, &OptIPAddressLeaseTime{LeaseTime: 43200}, o)
+
+ // Short byte stream
+ data = []byte{51, 4}
+ _, err = ParseOptIPAddressLeaseTime(data)
+ require.Error(t, err, "should get error from short byte stream")
+
+ // Wrong code
+ data = []byte{54, 4, 0, 0, 168, 192}
+ _, err = ParseOptIPAddressLeaseTime(data)
+ require.Error(t, err, "should get error from wrong code")
+
+ // Bad length
+ data = []byte{51, 5, 1, 1, 1, 1, 1}
+ _, err = ParseOptIPAddressLeaseTime(data)
+ require.Error(t, err, "should get error from bad length")
+}
+
+func TestOptIPAddressLeaseTimeString(t *testing.T) {
+ o := OptIPAddressLeaseTime{LeaseTime: 43200}
+ require.Equal(t, "IP Addresses Lease Time -> 43200", o.String())
+}