From 6bae0918796b6654d92f03386460833830459d1d Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sat, 4 Nov 2017 16:46:40 +0100 Subject: some tests for SA (cont'd) --- satp/security-association_test.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/satp/security-association_test.go b/satp/security-association_test.go index ab3592e..4bbf7b7 100644 --- a/satp/security-association_test.go +++ b/satp/security-association_test.go @@ -165,3 +165,38 @@ func TestSecurityAssociationEndpointUpdate(t *testing.T) { t.Fatalf("endpoints[2] is %v but should be %v", sa.endpoints[0], addr6) } } + +func TestSecurityAssociationEndpointCompareAndUpdate(t *testing.T) { + addr4, _ := net.ResolveUDPAddr("udp4", "1.2.3.4:444") + addr6, _ := net.ResolveUDPAddr("udp6", "[2a01:1234::2]:666") + + // should this panic?? + sa := NewSecurityAssociation(nil, 0, 0, 0) + sa.EndpointCompareAndUpdate(0, addr4) + + sa = NewSecurityAssociation(nil, 1, 0, 0) + + changed := sa.EndpointCompareAndUpdate(0, addr4) + if !EndpointsEqual(sa.endpoints[0], addr4) { + t.Fatalf("endpoints[0] is %v but should be %v", sa.endpoints[0], addr4) + } + if !changed { + t.Fatal("updateting a nil endpoint should return changed = true") + } + + changed = sa.EndpointCompareAndUpdate(0, addr4) + if !EndpointsEqual(sa.endpoints[0], addr4) { + t.Fatalf("endpoints[0] is %v but should be %v", sa.endpoints[0], addr4) + } + if changed { + t.Fatal("updateting endpoint with same address should return changed = false") + } + + changed = sa.EndpointCompareAndUpdate(0, addr6) + if !EndpointsEqual(sa.endpoints[0], addr6) { + t.Fatalf("endpoints[0] is %v but should be %v", sa.endpoints[0], addr6) + } + if !changed { + t.Fatalf("updateting endpoint %v with %v should return changed = true", addr4, addr6) + } +} -- cgit v1.2.3