-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathip_test.go
68 lines (51 loc) · 1.02 KB
/
ip_test.go
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestIPRanges(t *testing.T) {
inner := []string{
"127.0.0.1/32",
"172.16.0.0/24",
"172.16.123.45/32",
}
outer := []string{
"127.0.0.1/32",
"172.16.0.0/16",
}
res, err := ValidateIPRanges(inner, outer)
assert.NoError(t, err)
assert.Equal(t, res, inner)
}
func TestIPRangesNoInner(t *testing.T) {
inner := []string{}
outer := []string{
"127.0.0.1/32",
"172.16.0.0/16",
}
res, err := ValidateIPRanges(inner, outer)
assert.NoError(t, err)
assert.Equal(t, res, outer)
}
func TestIpRangesNoOuter(t *testing.T) {
inner := []string{
"127.0.0.1/32",
"172.16.0.0/24",
"172.16.123.45/32",
}
outer := []string{}
res, err := ValidateIPRanges(inner, outer)
assert.NoError(t, err)
assert.Equal(t, res, inner)
}
func TestIPRangesInvalid(t *testing.T) {
inner := []string{
"172.16.123.45/32",
}
outer := []string{
"172.16.128.0/17",
}
res, err := ValidateIPRanges(inner, outer)
assert.Error(t, err)
assert.Nil(t, res)
}