forked from billputer/go-namecheap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
namecheap_test.go
62 lines (51 loc) · 1.47 KB
/
namecheap_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
package namecheap
import (
"net/http"
"net/http/httptest"
"net/url"
"testing"
)
var (
mux *http.ServeMux
client *Client
server *httptest.Server
)
// This method of testing http client APIs is borrowed from
// Will Norris's work in go-github @ https://github.com/google/go-github
func setup() {
mux = http.NewServeMux()
server = httptest.NewServer(mux)
client = NewClient("anApiUser", "anToken", "anUser")
client.BaseURL = server.URL + "/"
}
func teardown() {
server.Close()
}
func testMethod(t *testing.T, r *http.Request, want string) {
if want != r.Method {
t.Errorf("Request method = %v, want %v", r.Method, want)
}
}
func TestNewClient(t *testing.T) {
c := NewClient("anApiUser", "anToken", "anUser")
if c.BaseURL != defaultBaseURL {
t.Errorf("NewClient BaseURL = %v, want %v", c.BaseURL, defaultBaseURL)
}
}
// Verify that the MakeRequest function assembles the correct API URL
func TestMakeRequest(t *testing.T) {
c := NewClient("anApiUser", "anToken", "anUser")
c.BaseURL = "https://fake-api-server/"
requestInfo := &ApiRequest{
method: "GET",
command: "namecheap.domains.getList",
params: url.Values{},
}
req, _ := c.makeRequest(requestInfo)
// correctly assembled URL
outURL := "https://fake-api-server/?ApiKey=anToken&ApiUser=anApiUser&ClientIp=127.0.0.1&Command=namecheap.domains.getList&UserName=anUser"
// test that URL was correctly assembled
if req.URL.String() != outURL {
t.Errorf("NewRequest() URL = %v, want %v", req.URL, outURL)
}
}