Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
add TestAzure
Browse files Browse the repository at this point in the history
  • Loading branch information
shawnps-sigsci committed Dec 1, 2016
1 parent 75e9568 commit 5ce3c3a
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions azure_test.go
@@ -0,0 +1,47 @@
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()
msazure = ts.URL
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")
}
}

0 comments on commit 5ce3c3a

Please sign in to comment.