forked from client9/ipcat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure_test.go
46 lines (41 loc) · 1.14 KB
/
azure_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
package ipcat
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
)
func TestAzure(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, `
<?xml version="1.0" encoding="utf-8"?>
<AzurePublicIpAddresses xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Region Name="europewest">
<IpRange Subnet="40.112.124.0/24" />
<IpRange Subnet="65.52.128.0/19" />
</Region>
<Region Name="useast">
<IpRange Subnet="23.96.0.0/18" />
<IpRange Subnet="23.96.64.0/28" />
</Region>
</AzurePublicIpAddresses>`)
}))
defer ts.Close()
findPublicIPsURL = func() (string, error) { return ts.URL, nil }
b, err := DownloadAzure()
if err != nil {
t.Fatalf("DownloadAzure() error: %v", err)
}
ipset := NewIntervalSet(100)
err = UpdateAzure(ipset, b)
if err != nil {
t.Fatalf("UpdateAzure error: %v", err)
}
rec, err := ipset.Contains("23.96.0.0")
if err != nil {
t.Fatalf("ipset.Contains(%q) error: %v", "23.96.0.0", err)
}
if rec == nil {
t.Errorf("ipset.Contains(%q) rec = nil, want exists", "23.96.0.0")
}
}