-
Notifications
You must be signed in to change notification settings - Fork 28
/
whoisguard_test.go
179 lines (159 loc) · 5.25 KB
/
whoisguard_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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package namecheap
import (
"fmt"
"net/http"
"net/url"
"reflect"
"testing"
)
func TestWhoisguardGetList(t *testing.T) {
setup()
defer teardown()
respXML := `<?xml version="1.0" encoding="UTF-8"?>
<ApiResponse xmlns="http://api.namecheap.com/xml.response" Status="OK">
<Errors />
<Warnings />
<RequestedCommand>namecheap.whoisguard.getList</RequestedCommand>
<CommandResponse Type="namecheap.whoisguard.getList">
<WhoisguardGetListResult>
<Whoisguard ID="34401" DomainName="" Created="12/18/2013" Expires="12/18/2014" Status="unused" />
<Whoisguard ID="34400" DomainName="test.com" Created="12/26/2013" Expires="12/26/2014" Status="enabled" />
</WhoisguardGetListResult>
<Paging>
<TotalItems>642</TotalItems>
<CurrentPage>1</CurrentPage>
<PageSize>20</PageSize>
</Paging>
</CommandResponse>
<Server>API01</Server>
<GMTTimeDifference>--5:00</GMTTimeDifference>
<ExecutionTime>0.029</ExecutionTime>
</ApiResponse>`
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
correctParams := fillDefaultParams(url.Values{})
correctParams.Set("Command", "namecheap.whoisguard.getList")
testBody(t, r, correctParams)
testMethod(t, r, "POST")
fmt.Fprint(w, respXML)
})
list, err := client.WhoisguardGetList()
if err != nil {
t.Errorf("WhoisguardGetList returned error: %v", err)
}
// WhoisguardGetListResult we expect, given the respXML above
want := []WhoisguardGetListResult{
WhoisguardGetListResult{
ID: 34401,
Created: "12/18/2013",
Expires: "12/18/2014",
Status: "unused",
},
WhoisguardGetListResult{
ID: 34400,
DomainName: "test.com",
Created: "12/26/2013",
Expires: "12/26/2014",
Status: "enabled",
},
}
if !reflect.DeepEqual(list, want) {
t.Errorf("WhoisguardGetList returned %+v, want %+v", list, want)
}
}
func TestWhoisguardEnable(t *testing.T) {
setup()
defer teardown()
respXML := `<?xml version="1.0" encoding="UTF-8"?>
<ApiResponse xmlns="http://api.namecheap.com/xml.response" Status="OK">
<Errors />
<Warnings />
<RequestedCommand>namecheap.whoisguard.enable</RequestedCommand>
<CommandResponse Type="namecheap.whoisguard.enable">
<WhoisguardEnableResult DomainName="domain1.com" IsSuccess="true" />
</CommandResponse>
<Server>API02</Server>
<GMTTimeDifference>--5:00</GMTTimeDifference>
<ExecutionTime>0.92</ExecutionTime>
</ApiResponse>`
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
correctParams := fillDefaultParams(url.Values{})
correctParams.Set("Command", "namecheap.whoisguard.enable")
correctParams.Set("WhoisguardID", "34401")
correctParams.Set("ForwardedToEmail", "[email protected]")
testBody(t, r, correctParams)
testMethod(t, r, "POST")
fmt.Fprint(w, respXML)
})
err := client.WhoisguardEnable(34401, "[email protected]")
if err != nil {
t.Errorf("WhoisguardEnable returned error: %v", err)
}
}
func TestWhoisguardDisable(t *testing.T) {
setup()
defer teardown()
respXML := `<?xml version="1.0" encoding="UTF-8"?>
<ApiResponse xmlns="http://api.namecheap.com/xml.response" Status="OK">
<Errors />
<Warnings />
<RequestedCommand>namecheap.whoisguard.disable</RequestedCommand>
<CommandResponse Type="namecheap.whoisguard.disable">
<WhoisguardDisableResult DomainName="domain1.com" IsSuccess="true" />
</CommandResponse>
<Server>API02</Server>
<GMTTimeDifference>--5:00</GMTTimeDifference>
<ExecutionTime>0.92</ExecutionTime>
</ApiResponse>`
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
correctParams := fillDefaultParams(url.Values{})
correctParams.Set("Command", "namecheap.whoisguard.disable")
correctParams.Set("WhoisguardID", "34401")
testBody(t, r, correctParams)
testMethod(t, r, "POST")
fmt.Fprint(w, respXML)
})
err := client.WhoisguardDisable(34401)
if err != nil {
t.Errorf("WhoisguardDisable returned error: %v", err)
}
}
func TestWhoisguardRenew(t *testing.T) {
setup()
defer teardown()
respXML := `<?xml version="1.0" encoding="UTF-8"?>
<ApiResponse xmlns="http://api.namecheap.com/xml.response" Status="OK">
<Errors />
<Warnings />
<RequestedCommand>namecheap.whoisguard.renew</RequestedCommand>
<CommandResponse Type="namecheap.whoisguard.renew">
<WhoisguardRenewResult WhoisguardId="38495" Years="1" Renew="true" OrderId="580938" TransactionId="884255" ChargedAmount="6.8000"/>
</CommandResponse>
<Server>API01</Server>
<GMTTimeDifference>--5:00</GMTTimeDifference>
<ExecutionTime>0.029</ExecutionTime>
</ApiResponse>`
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
correctParams := fillDefaultParams(url.Values{})
correctParams.Set("Command", "namecheap.whoisguard.renew")
correctParams.Set("WhoisguardID", "38495")
correctParams.Set("Years", "1")
testBody(t, r, correctParams)
testMethod(t, r, "POST")
fmt.Fprint(w, respXML)
})
result, err := client.WhoisguardRenew(38495, 1)
if err != nil {
t.Errorf("WhoisguardRenew returned error: %v", err)
}
// DomainCheckResult we expect, given the respXML above
want := &WhoisguardRenewResult{
WhoisguardID: 38495,
Renewed: true,
ChargedAmount: 6.8,
TransactionID: 884255,
OrderID: 580938,
}
if !reflect.DeepEqual(result, want) {
t.Errorf("WhoisguardRenew returned %+v, want %+v", result, want)
}
}