summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@anytun.org>2017-11-04 16:46:40 +0100
committerChristian Pointner <equinox@anytun.org>2017-11-04 16:46:40 +0100
commit6bae0918796b6654d92f03386460833830459d1d (patch)
tree9323dd6d06d2b94611c5de14c5e17218d6f51db8
parentsome tests for SA (diff)
some tests for SA (cont'd)
-rw-r--r--satp/security-association_test.go35
1 files changed, 35 insertions, 0 deletions
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)
+ }
+}