diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-10-07 13:56:56 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-07 13:56:56 -0400 |
commit | 9ae873e60e149677db66782eaf2b4ed1402e97d2 (patch) | |
tree | 1f72e0558316390e8a235edad0f2464725dbd9c9 /libpod/network/network_test.go | |
parent | 173e3c2faa74e5ef1b941338c06e5dd7dca68ac2 (diff) | |
parent | fe3faa517e1bbc3b2e82afaae32d8712c844fdae (diff) | |
download | podman-9ae873e60e149677db66782eaf2b4ed1402e97d2.tar.gz podman-9ae873e60e149677db66782eaf2b4ed1402e97d2.tar.bz2 podman-9ae873e60e149677db66782eaf2b4ed1402e97d2.zip |
Merge pull request #7943 from baude/issue7807
prevent unpredictable results with network create|remove
Diffstat (limited to 'libpod/network/network_test.go')
-rw-r--r-- | libpod/network/network_test.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/libpod/network/network_test.go b/libpod/network/network_test.go new file mode 100644 index 000000000..1969e792c --- /dev/null +++ b/libpod/network/network_test.go @@ -0,0 +1,35 @@ +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 { + test := tt + t.Run(tt.name, func(t *testing.T) { + if got := networkIntersect(test.args.n1, test.args.n2); got != test.want { + t.Errorf("networkIntersect() = %v, want %v", got, test.want) + } + }) + } +} |