forked from cloudflare/cloudflare-go
/
intelligence_whois_test.go
77 lines (69 loc) · 2.13 KB
/
intelligence_whois_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
package cloudflare
import (
"context"
"fmt"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestIntelligence_WHOIS(t *testing.T) {
setup()
defer teardown()
mux.HandleFunc("/accounts/"+testAccountID+"/intel/whois", 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": {
"domain": "cloudflare.com",
"created_date": "2009-02-17",
"updated_date": "2017-05-24",
"registrant": "DATA REDACTED",
"registrant_org": "DATA REDACTED",
"registrant_country": "United States",
"registrant_email": "https://domaincontact.cloudflareregistrar.com/cloudflare.com",
"registrar": "Cloudflare, Inc.",
"nameservers": [
"ns3.cloudflare.com",
"ns4.cloudflare.com",
"ns5.cloudflare.com",
"ns6.cloudflare.com",
"ns7.cloudflare.com"
]
}
}`)
})
// Make sure missing account ID is thrown
_, err := client.IntelligenceWHOIS(context.Background(), WHOISParameters{})
if assert.Error(t, err) {
assert.Equal(t, ErrMissingAccountID, err)
}
// Make sure missing domain is thrown
_, err = client.IntelligenceWHOIS(context.Background(), WHOISParameters{AccountID: testAccountID})
if assert.Error(t, err) {
assert.Equal(t, ErrMissingDomain, err)
}
want := WHOIS{
Domain: "cloudflare.com",
CreatedDate: "2009-02-17",
UpdatedDate: "2017-05-24",
Registrant: "DATA REDACTED",
RegistrantOrg: "DATA REDACTED",
RegistrantCountry: "United States",
RegistrantEmail: "https://domaincontact.cloudflareregistrar.com/cloudflare.com",
Registrar: "Cloudflare, Inc.",
Nameservers: []string{
"ns3.cloudflare.com",
"ns4.cloudflare.com",
"ns5.cloudflare.com",
"ns6.cloudflare.com",
"ns7.cloudflare.com",
},
}
out, err := client.IntelligenceWHOIS(context.Background(), WHOISParameters{AccountID: testAccountID, Domain: "cloudflare.com"})
if assert.NoError(t, err) {
assert.Equal(t, out, want, "structs not equal")
}
}