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_iapd_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_iapd_test.go')
-rw-r--r-- | dhcpv6/option_iapd_test.go | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/dhcpv6/option_iapd_test.go b/dhcpv6/option_iapd_test.go index 2fce999..398a23e 100644 --- a/dhcpv6/option_iapd_test.go +++ b/dhcpv6/option_iapd_test.go @@ -2,12 +2,50 @@ package dhcpv6 import ( "net" + "reflect" "testing" "time" "github.com/stretchr/testify/require" ) +func TestParseMessageWithIAPD(t *testing.T) { + data := []byte{ + 0, 25, // IAPD option code + 0, 41, // length + 1, 0, 0, 0, // IAID + 0, 0, 0, 1, // T1 + 0, 0, 0, 2, // T2 + 0, 26, 0, 25, // 26 = IAPrefix Option, 25 = length + 0, 0, 0, 2, // IAPrefix preferredLifetime + 0, 0, 0, 4, // IAPrefix validLifetime + 36, // IAPrefix prefixLength + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, // IAPrefix ipv6Prefix + } + var got MessageOptions + if err := got.FromBytes(data); err != nil { + t.Errorf("FromBytes = %v", err) + } + + want := &OptIAPD{ + IaId: [4]byte{1, 0, 0, 0}, + T1: 1 * time.Second, + T2: 2 * time.Second, + Options: PDOptions{Options: Options{&OptIAPrefix{ + PreferredLifetime: 2 * time.Second, + ValidLifetime: 4 * time.Second, + Prefix: &net.IPNet{ + Mask: net.CIDRMask(36, 128), + IP: net.IP{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, + }, + Options: PrefixOptions{Options: Options{}}, + }}}, + } + if gotIAPD := got.OneIAPD(); !reflect.DeepEqual(gotIAPD, want) { + t.Errorf("OneIAPD = %v, want %v", gotIAPD, want) + } +} + func TestOptIAPDParseOptIAPD(t *testing.T) { data := []byte{ 1, 0, 0, 0, // IAID |