-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter_test.go
52 lines (45 loc) · 1.1 KB
/
filter_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
package rip
import (
"testing"
)
func TestFilterPublicAddress(t *testing.T) {
testData := []struct {
ips []string
expected string
}{
{[]string{"127.0.0.0"}, ""},
{[]string{"10.0.0.0"}, ""},
{[]string{"169.254.0.0"}, ""},
{[]string{"192.168.0.0"}, ""},
{[]string{"::1"}, ""},
{[]string{"fc00::"}, ""},
{[]string{"172.15.0.0"}, "172.15.0.0"},
{[]string{"172.16.0.0"}, ""},
{[]string{"172.31.0.0"}, ""},
{[]string{"172.32.0.0"}, "172.32.0.0"},
{[]string{"147.12.56.11"}, "147.12.56.11"},
}
for _, tt := range testData {
addr, _ := FilterPublicAddress(tt.ips)
if addr != tt.expected {
t.Errorf("unexpected result, want: '%s', got: '%s'", tt.expected, addr)
}
}
}
func TestFilterAWS(t *testing.T) {
testData := []struct {
ips []string
expected string
}{
{[]string{}, ""},
{[]string{""}, ""},
{[]string{"127.0.0.1"}, "127.0.0.1"},
{[]string{"127.0.0.1", "147.12.56.11"}, "147.12.56.11"},
}
for _, tt := range testData {
addr, _ := FilterAWS(tt.ips)
if addr != tt.expected {
t.Errorf("unexpected result, want: '%s', got: '%s'", tt.expected, addr)
}
}
}