summaryrefslogtreecommitdiff
path: root/pkg/network/network_test.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-09-09 19:44:57 +0200
committerGitHub <noreply@github.com>2019-09-09 19:44:57 +0200
commit7042a3d7a539bae79ed63bdc87f432b8ec73afd8 (patch)
tree6f229373f5e436663c8908d0f2409fdbac2f6a2a /pkg/network/network_test.go
parent511b0717454e0619d9d7d201cb10a41201cebef2 (diff)
parentee432cf2792c5dbe81953007f1fd5c87beb3ebd5 (diff)
downloadpodman-7042a3d7a539bae79ed63bdc87f432b8ec73afd8.tar.gz
podman-7042a3d7a539bae79ed63bdc87f432b8ec73afd8.tar.bz2
podman-7042a3d7a539bae79ed63bdc87f432b8ec73afd8.zip
Merge pull request #3862 from baude/networkcreate
podman network create
Diffstat (limited to 'pkg/network/network_test.go')
-rw-r--r--pkg/network/network_test.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/pkg/network/network_test.go b/pkg/network/network_test.go
new file mode 100644
index 000000000..dbffc33ad
--- /dev/null
+++ b/pkg/network/network_test.go
@@ -0,0 +1,34 @@
+package network
+
+import (
+ "net"
+ "testing"
+)
+
+func parseCIDR(n string) *net.IPNet {
+ _, parsedNet, _ := net.ParseCIDR(n)
+ return parsedNet
+}
+
+func Test_networkIntersect(t *testing.T) {
+ type args struct {
+ n1 *net.IPNet
+ n2 *net.IPNet
+ }
+ tests := []struct {
+ name string
+ args args
+ want bool
+ }{
+ {"16 and 24 intersects", args{n1: parseCIDR("192.168.0.0/16"), n2: parseCIDR("192.168.1.0/24")}, true},
+ {"24 and 25 intersects", args{n1: parseCIDR("192.168.1.0/24"), n2: parseCIDR("192.168.1.0/25")}, true},
+ {"Two 24s", args{n1: parseCIDR("192.168.1.0/24"), n2: parseCIDR("192.168.2.0/24")}, false},
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := networkIntersect(tt.args.n1, tt.args.n2); got != tt.want {
+ t.Errorf("networkIntersect() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}