summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/option_ip_address_lease_time_test.go
blob: 384db1ce29f692c2bc0ddfc76f576b8f3a7f3f99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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, []byte{0, 0, 168, 192}, o.ToBytes(), "ToBytes")
}

func TestParseOptIPAddressLeaseTime(t *testing.T) {
	data := []byte{0, 0, 168, 192}
	o, err := ParseOptIPAddressLeaseTime(data)
	require.NoError(t, err)
	require.Equal(t, &OptIPAddressLeaseTime{LeaseTime: 43200}, o)

	// Short byte stream
	data = []byte{168, 192}
	_, err = ParseOptIPAddressLeaseTime(data)
	require.Error(t, err, "should get error from short byte stream")

	// Bad length
	data = []byte{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())
}