forked from cloudflare/cloudflare-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintelligence_asn_test.go
111 lines (98 loc) · 3.03 KB
/
intelligence_asn_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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package cloudflare
import (
"context"
"fmt"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
const testASNNumber = "13335"
func TestIntelligence_ASNOverview(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/accounts/"+testAccountID+"/intel/asn/"+testASNNumber, func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodGet, r.Method, "Expected method 'GET', got %s", r.Method)
w.Header().Set("content-type", "application/json")
fmt.Fprint(w, `{
"success": true,
"errors": [],
"messages": [],
"result": [
{
"asn": 13335,
"description": "CLOUDFLARENET",
"country": "US",
"type": "hosting_provider",
"domain_count": 1,
"top_domains": [
"example.com"
]
}
]
}`)
})
// Make sure missing account ID is thrown
_, err := client.IntelligenceASNOverview(context.Background(), IntelligenceASNOverviewParameters{})
if assert.Error(t, err) {
assert.Equal(t, ErrMissingAccountID, err)
}
// Make sure missing ASN is thrown
_, err = client.IntelligenceASNOverview(context.Background(), IntelligenceASNOverviewParameters{AccountID: testAccountID})
if assert.Error(t, err) {
assert.Equal(t, ErrMissingASN, err)
}
want := ASNInfo{
ASN: 13335,
Description: "CLOUDFLARENET",
Country: "US",
Type: "hosting_provider",
DomainCount: 1,
TopDomains: []string{"example.com"},
}
out, err := client.IntelligenceASNOverview(context.Background(), IntelligenceASNOverviewParameters{AccountID: testAccountID, ASN: 13335})
if assert.NoError(t, err) {
assert.Equal(t, len(out), 1, "Length of ASN overview not expected")
assert.Equal(t, out[0], want, "structs not equal")
}
}
func TestIntelligence_ASNSubnet(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/accounts/"+testAccountID+"/intel/asn/"+testASNNumber+"/subnets", func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodGet, r.Method, "Expected method 'GET', got %s", r.Method)
w.Header().Set("content-type", "application/json")
fmt.Fprint(w, `{
"asn": 13335,
"ip_count_total": 1,
"subnets": [
"192.0.2.0/24",
"2001:DB8::/32"
],
"count": 1,
"page": 1,
"per_page": 20
}`)
})
// Make sure missing account ID is thrown
_, err := client.IntelligenceASNSubnets(context.Background(), IntelligenceASNSubnetsParameters{})
if assert.Error(t, err) {
assert.Equal(t, ErrMissingAccountID, err)
}
// Make sure missing ASN is thrown
_, err = client.IntelligenceASNSubnets(context.Background(), IntelligenceASNSubnetsParameters{AccountID: testAccountID})
if assert.Error(t, err) {
assert.Equal(t, ErrMissingASN, err)
}
want := IntelligenceASNSubnetResponse{
ASN: 13335,
IPCountTotal: 1,
Subnets: []string{"192.0.2.0/24", "2001:DB8::/32"},
Count: 1,
Page: 1,
PerPage: 20,
}
out, err := client.IntelligenceASNSubnets(context.Background(), IntelligenceASNSubnetsParameters{AccountID: testAccountID, ASN: 13335})
if assert.NoError(t, err) {
assert.Equal(t, out, want, "structs not equal")
}
}