summaryrefslogtreecommitdiff
path: root/libpod/network/network_test.go
blob: 1969e792cb2e02c84939cab7cd9742c9f54e84f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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)
			}
		})
	}
}