diff options
author | Andrea Barberio <insomniac@slackware.it> | 2017-12-23 12:40:15 +0000 |
---|---|---|
committer | Andrea Barberio <insomniac@slackware.it> | 2017-12-23 12:40:15 +0000 |
commit | 2e6fcaa0253bcf494ad41e29a4b21a7f28d43b0d (patch) | |
tree | 13c3ce62744ee12917b3e4a36fde1be15b6d6d9e | |
parent | 522537fb5eebceb57ed5f2b39101a854e97b4da9 (diff) |
Added setters and getter testing for DHCPv6Relay
-rw-r--r-- | dhcpv6/dhcpv6relay.go | 1 | ||||
-rw-r--r-- | dhcpv6/dhcpv6relay_test.go | 42 |
2 files changed, 37 insertions, 6 deletions
diff --git a/dhcpv6/dhcpv6relay.go b/dhcpv6/dhcpv6relay.go index 042168a..fae01bf 100644 --- a/dhcpv6/dhcpv6relay.go +++ b/dhcpv6/dhcpv6relay.go @@ -66,6 +66,7 @@ func (r *DHCPv6Relay) MessageType() MessageType { } func (r *DHCPv6Relay) SetMessageType(messageType MessageType) { + // not enforcing if message type is not a RELAY_FORW or a RELAY_REPL message r.messageType = messageType } diff --git a/dhcpv6/dhcpv6relay_test.go b/dhcpv6/dhcpv6relay_test.go index a128993..983a882 100644 --- a/dhcpv6/dhcpv6relay_test.go +++ b/dhcpv6/dhcpv6relay_test.go @@ -9,7 +9,7 @@ import ( func TestDHCPv6Relay(t *testing.T) { ll := net.IP{0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xbb, 0xcc, 0xff, 0xfe, 0xdd, 0xee, 0xff} ma := net.IP{0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01} - d := DHCPv6Relay{ + r := DHCPv6Relay{ messageType: RELAY_FORW, hopCount: 10, linkAddr: ll, @@ -17,19 +17,49 @@ func TestDHCPv6Relay(t *testing.T) { // options is left empty here for testing purposes, even if it's // mandatory to have at least a relay message option } - if mt := d.MessageType(); mt != RELAY_FORW { + if mt := r.MessageType(); mt != RELAY_FORW { t.Fatalf("Invalid message type. Expected %v, got %v", RELAY_FORW, mt) } - if hc := d.HopCount(); hc != 10 { + if hc := r.HopCount(); hc != 10 { t.Fatalf("Invalid hop count. Expected 10, got %v", hc) } - if la := d.LinkAddr(); !bytes.Equal(la, ll) { + if la := r.LinkAddr(); !bytes.Equal(la, ll) { t.Fatalf("Invalid link address. Expected %v, got %v", ll, la) } - if pa := d.PeerAddr(); !bytes.Equal(pa, ma) { + if pa := r.PeerAddr(); !bytes.Equal(pa, ma) { t.Fatalf("Invalid peer address. Expected %v, got %v", ma, pa) } - if opts := d.Options(); len(opts) != 0 { + if opts := r.Options(); len(opts) != 0 { t.Fatalf("Invalid options. Expected none, got %v", opts) } } + +func TestDHCPv6RelaySettersAndGetters(t *testing.T) { + r := DHCPv6Relay{} + // set and get message type + r.SetMessageType(RELAY_REPL) + if mt := r.MessageType(); mt != RELAY_REPL { + t.Fatalf("Invalid message type. Expected %v, got %v", RELAY_REPL, mt) + } + // set and get hop count + r.SetHopCount(5) + if hc := r.HopCount(); hc != 5 { + t.Fatalf("Invalid hop count. Expected 5, got %v", hc) + } + // set and get link address + r.SetLinkAddr(net.IPv6loopback) + if la := r.LinkAddr(); !bytes.Equal(la, net.IPv6loopback) { + t.Fatalf("Invalid link address. Expected %v, got %v", net.IPv6loopback, la) + } + // set and get peer address + r.SetPeerAddr(net.IPv6loopback) + if pa := r.PeerAddr(); !bytes.Equal(pa, net.IPv6loopback) { + t.Fatalf("Invalid peer address. Expected %v, got %v", net.IPv6loopback, pa) + } + // set and get options + oneOpt := []Option{&OptRelayMsg{relayMessage: &DHCPv6Message{}}} + r.SetOptions(oneOpt) + if opts := r.Options(); len(opts) != 1 || opts[0] != oneOpt[0] { + t.Fatalf("Invalid options. Expected %v, got %v", oneOpt, opts) + } +} |