forked from client9/ipcat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaws_test.go
57 lines (54 loc) · 1.23 KB
/
aws_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
package ipcat
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
)
func TestAWS(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, `
{
"syncToken": "0123456789",
"createDate": "2016-11-30-23-19-08",
"prefixes": [
{
"ip_prefix": "216.182.224.0/20",
"region": "us-east-1",
"service": "AMAZON"
},
{
"ip_prefix": "13.54.0.0/15",
"region": "ap-southeast-2",
"service": "EC2"
}
]
}`)
}))
awsDownload = ts.URL
defer ts.Close()
b, err := DownloadAWS()
if err != nil {
t.Fatalf("DownloadAWS() error: %v", err)
}
ipset := NewIntervalSet(100)
err = UpdateAWS(ipset, b)
if err != nil {
t.Fatalf("UpdateAWS error: %v", err)
}
// UpdateAWS should only add EC2 IP ranges
rec, err := ipset.Contains("216.182.224.0")
if err != nil {
t.Fatalf("ipset.Contains(%q) error: %v", "216.182.224.0", err)
}
if rec != nil {
t.Errorf("ipset.Contains(%q) rec = %v, want nil", "216.182.224.0", rec)
}
rec, err = ipset.Contains("13.54.0.1")
if err != nil {
t.Fatalf("ipset.Contains(%q) error: %v", "13.54.0.0", err)
}
if rec == nil {
t.Errorf("ipset.Contains(%q) rec = nil, want exists", "13.54.0.0")
}
}