summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/dhcpv6relay_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'dhcpv6/dhcpv6relay_test.go')
-rw-r--r--dhcpv6/dhcpv6relay_test.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/dhcpv6/dhcpv6relay_test.go b/dhcpv6/dhcpv6relay_test.go
index c5989e5..e08e6a4 100644
--- a/dhcpv6/dhcpv6relay_test.go
+++ b/dhcpv6/dhcpv6relay_test.go
@@ -4,6 +4,8 @@ import (
"bytes"
"net"
"testing"
+
+ "github.com/stretchr/testify/require"
)
func TestDHCPv6Relay(t *testing.T) {
@@ -104,3 +106,35 @@ func TestDHCPv6RelayToBytes(t *testing.T) {
t.Fatalf("Invalid ToBytes result. Expected %v, got %v", expected, relayBytes)
}
}
+
+func TestNewRelayRepFromRelayForw(t *testing.T) {
+ rf := DHCPv6Relay{}
+ rf.SetMessageType(RELAY_FORW)
+ rf.SetPeerAddr(net.IPv6linklocalallrouters)
+ rf.SetLinkAddr(net.IPv6interfacelocalallnodes)
+ oro := OptRelayMsg{}
+ s := DHCPv6Message{}
+ s.SetMessage(SOLICIT)
+ cid := OptClientId{}
+ s.AddOption(&cid)
+ oro.SetRelayMessage(&s)
+ rf.AddOption(&oro)
+
+ a, err := NewAdvertiseFromSolicit(&s)
+ require.NoError(t, err)
+ rr, err := NewRelayReplFromRelayForw(&rf, a)
+ require.NoError(t, err)
+ relay := rr.(*DHCPv6Relay)
+ require.Equal(t, rr.Type(), RELAY_REPL)
+ require.Equal(t, relay.HopCount(), rf.HopCount())
+ require.Equal(t, relay.PeerAddr(), rf.PeerAddr())
+ require.Equal(t, relay.LinkAddr(), rf.LinkAddr())
+ m, err := relay.GetInnerMessage()
+ require.NoError(t, err)
+ require.Equal(t, m, a)
+
+ rr, err = NewRelayReplFromRelayForw(nil, a)
+ require.Error(t, err)
+ rr, err = NewRelayReplFromRelayForw(&rf, nil)
+ require.Error(t, err)
+}