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_temporaryaddress_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_temporaryaddress_test.go')
-rw-r--r-- | dhcpv6/option_temporaryaddress_test.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/dhcpv6/option_temporaryaddress_test.go b/dhcpv6/option_temporaryaddress_test.go index 8704d5c..6d94f8f 100644 --- a/dhcpv6/option_temporaryaddress_test.go +++ b/dhcpv6/option_temporaryaddress_test.go @@ -2,12 +2,42 @@ package dhcpv6 import ( "net" + "reflect" "testing" "time" "github.com/stretchr/testify/require" ) +func TestParseMessageWithIATA(t *testing.T) { + data := []byte{ + 0, 4, // IATA option code + 0, 32, // length + 1, 0, 0, 0, // IAID + // IATA Options + 0, 5, 0, 0x18, 0x24, 1, 0xdb, 0, 0x30, 0x10, 0xc0, 0x8f, 0xfa, 0xce, 0, 0, 0, 0x44, 0, 0, // IP + 0, 0, 0, 2, // PreferredLifetime + 0, 0, 0, 4, // ValidLifetime + } + var got MessageOptions + if err := got.FromBytes(data); err != nil { + t.Errorf("FromBytes = %v", err) + } + + want := &OptIATA{ + IaId: [4]byte{1, 0, 0, 0}, + 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 gotIATA := got.OneIATA(); !reflect.DeepEqual(gotIATA, want) { + t.Errorf("OneIATA = %v, want %v", gotIATA, want) + } +} + func TestOptIATAParseOptIATA(t *testing.T) { data := []byte{ 1, 0, 0, 0, // IAID |