summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/option_iaprefix_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'dhcpv6/option_iaprefix_test.go')
-rw-r--r--dhcpv6/option_iaprefix_test.go29
1 files changed, 11 insertions, 18 deletions
diff --git a/dhcpv6/option_iaprefix_test.go b/dhcpv6/option_iaprefix_test.go
index f7b5b6b..2c4dea4 100644
--- a/dhcpv6/option_iaprefix_test.go
+++ b/dhcpv6/option_iaprefix_test.go
@@ -14,15 +14,16 @@ func TestOptIAPrefix(t *testing.T) {
0xee, 0xff, 0x00, 0x11, // validLifetime
36, // prefixLength
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, // ipv6Prefix
+ 0, 8, 0, 2, 0xaa, 0xbb, // options
}
opt, err := ParseOptIAPrefix(buf)
if err != nil {
t.Fatal(err)
}
- if pl := opt.PreferredLifetime(); pl != 0xaabbccdd {
+ if pl := opt.PreferredLifetime; pl != 0xaabbccdd {
t.Fatalf("Invalid Preferred Lifetime. Expected 0xaabbccdd, got %v", pl)
}
- if vl := opt.ValidLifetime(); vl != 0xeeff0011 {
+ if vl := opt.ValidLifetime; vl != 0xeeff0011 {
t.Fatalf("Invalid Valid Lifetime. Expected 0xeeff0011, got %v", vl)
}
if pr := opt.PrefixLength(); pr != 36 {
@@ -31,6 +32,9 @@ func TestOptIAPrefix(t *testing.T) {
if ip := opt.IPv6Prefix(); !bytes.Equal(ip, net.IPv6loopback) {
t.Fatalf("Invalid Prefix Length. Expected %v, got %v", net.IPv6loopback, ip)
}
+ if opt.Length() != len(buf) {
+ t.Fatalf("Invalid Option Length. Expected %v, got %v", len(buf), opt.Length())
+ }
}
func TestOptIAPrefixToBytes(t *testing.T) {
@@ -39,14 +43,17 @@ func TestOptIAPrefixToBytes(t *testing.T) {
0xee, 0xff, 0x00, 0x11, // validLifetime
36, // prefixLength
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ipv6Prefix
+ 0, 8, 0, 2, 0xaa, 0xbb, // options
}
expected := []byte{00, 26, 00, byte(len(buf))}
expected = append(expected, buf...)
opt := OptIAPrefix{
- preferredLifetime: 0xaabbccdd,
- validLifetime: 0xeeff0011,
+ PreferredLifetime: 0xaabbccdd,
+ ValidLifetime: 0xeeff0011,
prefixLength: 36,
+ ipv6Prefix: net.IPv6zero,
}
+ opt.Options = append(opt.Options, &OptElapsedTime{ElapsedTime: 0xaabb})
toBytes := opt.ToBytes()
if !bytes.Equal(toBytes, expected) {
t.Fatalf("Invalid ToBytes result. Expected %v, got %v", expected, toBytes)
@@ -65,20 +72,6 @@ func TestOptIAPrefixParseInvalidTooShort(t *testing.T) {
}
}
-func TestOptIAPrefixSetGetOptions(t *testing.T) {
- opt := OptIAPrefix{
- preferredLifetime: 0xaabbccdd,
- validLifetime: 0xeeff0011,
- }
- expected := []byte{
- 0, 8, 0, 2, 0xaa, 0xbb, // options
- }
-
- require.Equal(t, []byte(nil), opt.Options(), "Options() should be blank by default")
- opt.SetOptions(expected)
- require.Equal(t, expected, opt.Options(), "Options() did not contain the correct data")
-}
-
func TestOptIAPrefixString(t *testing.T) {
buf := []byte{
0xaa, 0xbb, 0xcc, 0xdd, // preferredLifetime