diff options
author | Chris Koch <chrisko@google.com> | 2023-02-19 13:59:24 -0800 |
---|---|---|
committer | Chris K <c@chrisko.ch> | 2023-02-19 22:39:16 -0800 |
commit | 5369909a5de7c157e56e0feebbfde0b190e7a614 (patch) | |
tree | d72fdc57ca90546c5578f1949a95c9945615642a /dhcpv6/option_nontemporaryaddress_test.go | |
parent | a3bc2a6d841c820e7297fe54731f8d91d0721426 (diff) |
Tests for option deserialization & getters
Tests that for the correct option code, the correct deserialization is
applied.
Signed-off-by: Chris Koch <chrisko@google.com>
Diffstat (limited to 'dhcpv6/option_nontemporaryaddress_test.go')
-rw-r--r-- | dhcpv6/option_nontemporaryaddress_test.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/dhcpv6/option_nontemporaryaddress_test.go b/dhcpv6/option_nontemporaryaddress_test.go index a1105d3..3e5c55b 100644 --- a/dhcpv6/option_nontemporaryaddress_test.go +++ b/dhcpv6/option_nontemporaryaddress_test.go @@ -2,12 +2,43 @@ package dhcpv6 import ( "net" + "reflect" "testing" "time" "github.com/stretchr/testify/require" ) +func TestParseMessageWithIANA(t *testing.T) { + data := []byte{ + 0, 3, // IANA option code + 0, 40, // length + 1, 0, 0, 0, // IAID + 0, 0, 0, 1, // T1 + 0, 0, 0, 2, // T2 + 0, 5, 0, 0x18, 0x24, 1, 0xdb, 0, 0x30, 0x10, 0xc0, 0x8f, 0xfa, 0xce, 0, 0, 0, 0x44, 0, 0, 0, 0, 0, 2, 0, 0, 0, 4, // options + } + var got MessageOptions + if err := got.FromBytes(data); err != nil { + t.Errorf("FromBytes = %v", err) + } + + want := &OptIANA{ + IaId: [4]byte{1, 0, 0, 0}, + T1: 1 * time.Second, + T2: 2 * time.Second, + Options: IdentityOptions{Options: Options{&OptIAAddress{ + IPv6Addr: net.IP{0x24, 1, 0xdb, 0, 0x30, 0x10, 0xc0, 0x8f, 0xfa, 0xce, 0, 0, 0, 0x44, 0, 0}, + PreferredLifetime: 2 * time.Second, + ValidLifetime: 4 * time.Second, + Options: AddressOptions{Options: Options{}}, + }}}, + } + if gotIANA := got.OneIANA(); !reflect.DeepEqual(gotIANA, want) { + t.Errorf("OneIANA = %v, want %v", gotIANA, want) + } +} + func TestOptIANAParseOptIANA(t *testing.T) { data := []byte{ 1, 0, 0, 0, // IAID |