aboutsummaryrefslogtreecommitdiff
path: root/pkg/ipstack/ipstack_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/ipstack/ipstack_test.go')
-rw-r--r--pkg/ipstack/ipstack_test.go31
1 files changed, 12 insertions, 19 deletions
diff --git a/pkg/ipstack/ipstack_test.go b/pkg/ipstack/ipstack_test.go
index 5cef903..e782f67 100644
--- a/pkg/ipstack/ipstack_test.go
+++ b/pkg/ipstack/ipstack_test.go
@@ -250,31 +250,20 @@ import (
//}
func TestIntersect(t *testing.T) {
- net1 := netip.MustParsePrefix("1.1.1.1/24")
+ net1 := netip.MustParsePrefix("10.0.0.0/24")
net2 := netip.MustParsePrefix("1.1.1.2/24")
net3 := netip.MustParsePrefix("1.0.0.1/24")
net4 := netip.MustParsePrefix("0.0.0.0/0") // default route
- net5 := netip.MustParsePrefix("1.1.1.1/32")
+ net5 := netip.MustParsePrefix("10.2.0.3/32")
- res00 := intersect(net1, net5)
- if !res00 {
- t.Error("net1 and net2 should intersect")
+ res00 := intersect(net5, net1)
+ if res00 {
+ t.Error("net5 -> net1 should not intersect")
t.Fail()
}
- res01 := intersect(net5, net1)
- if res01 {
- t.Error("net1 and net2 should not intersect")
- t.Fail()
- }
-
- res1 := intersect(net1, net2)
- if !res1 {
- t.Error("net1 and net2 should intersect")
- t.Fail()
- }
- res0 := intersect(net2, net1)
- if !res0 {
- t.Error("net1 and net2 should intersect")
+ res01 := intersect(net5, net4)
+ if !res01 {
+ t.Error("net5 -> net4 should intersect")
t.Fail()
}
@@ -306,3 +295,7 @@ func TestIntersect(t *testing.T) {
fmt.Println("TestIntersect successful")
}
+
+func intersect(n1, n2 netip.Prefix) bool {
+ return n1.Overlaps(n2)
+}