diff options
author | David Barr <38654497+davebarrau@users.noreply.github.com> | 2018-10-12 11:09:04 +1100 |
---|---|---|
committer | insomniac <insomniacslk@users.noreply.github.com> | 2018-10-11 17:09:04 -0700 |
commit | dc01165c86340093eacf62c0856ae4e2164a4845 (patch) | |
tree | 9ca76ae4103c3e63cd86620fdec230e5cfe5b78d /dhcpv6/option_remoteid_test.go | |
parent | ee671d361777cc640550bab38cc6b0d412396f80 (diff) |
Add some more DHCPv6 option tests. (#171)
* Add some more DHCPv6 option tests.
* Remove AddRequestedOption() duplicate detection test due to failing on Go 1.9
Diffstat (limited to 'dhcpv6/option_remoteid_test.go')
-rw-r--r-- | dhcpv6/option_remoteid_test.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/dhcpv6/option_remoteid_test.go b/dhcpv6/option_remoteid_test.go index b2ef3cc..bc13d43 100644 --- a/dhcpv6/option_remoteid_test.go +++ b/dhcpv6/option_remoteid_test.go @@ -3,6 +3,8 @@ package dhcpv6 import ( "bytes" "testing" + + "github.com/stretchr/testify/require" ) func TestOptRemoteId(t *testing.T) { @@ -36,3 +38,42 @@ func TestOptRemoteIdToBytes(t *testing.T) { t.Fatalf("Invalid ToBytes result. Expected %v, got %v", expected, toBytes) } } + +func TestOptRemoteIdSet(t *testing.T) { + enterpriseNumber := uint32(12345) + remoteID := []byte("DSLAM01 eth2/1/01/21") + opt := OptRemoteId{} + opt.SetEnterpriseNumber(enterpriseNumber) + opt.SetRemoteID(remoteID) + + require.Equal(t, uint32(12345), opt.EnterpriseNumber()) + require.Equal(t, []byte("DSLAM01 eth2/1/01/21"), opt.RemoteID()) +} + +func TestOptRemoteIdParseOptRemoteIdTooShort(t *testing.T) { + buf := []byte{0xaa, 0xbb, 0xcc} + _, err := ParseOptRemoteId(buf) + require.Error(t, err, "A short option should return an error") +} + +func TestOptRemoteIdString(t *testing.T) { + buf := []byte{0xaa, 0xbb, 0xcc, 0xdd} + remoteId := []byte("Test1234") + buf = append(buf, remoteId...) + + opt, err := ParseOptRemoteId(buf) + require.NoError(t, err) + str := opt.String() + require.Contains( + t, + str, + "enterprisenum=2864434397", + "String() should contain the enterprisenum", + ) + require.Contains( + t, + str, + "remoteid=[84 101 115 116 49 50 51 52]", + "String() should contain the remoteid bytes", + ) +} |