forked from liushiqi1001/dnspod-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dnspod_test.go
55 lines (43 loc) · 1.29 KB
/
dnspod_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
package dnspod
import (
"net/http"
"net/http/httptest"
"testing"
)
func setupClient() (*Client, *http.ServeMux, func()) {
mux := http.NewServeMux()
server := httptest.NewServer(mux)
params := CommonParams{LoginToken: "dnspod login token"}
client := NewClient(params)
client.BaseURL = server.URL + "/"
return client, mux, func() {
server.Close()
}
}
func TestNewClient(t *testing.T) {
params := CommonParams{LoginToken: "dnspod login token"}
client := NewClient(params)
if client.BaseURL != defaultBaseURL {
t.Errorf("got %v, want %v", client.BaseURL, defaultBaseURL)
}
}
func TestNewRequest(t *testing.T) {
params := CommonParams{LoginToken: "dnspod login token"}
client := NewClient(params)
client.BaseURL = "https://go.example.com/"
inPath := "foo"
req, err := client.NewRequest(http.MethodGet, inPath, nil)
if err != nil {
t.Fatal(err)
}
// test that relative URL was expanded with the proper BaseURL
outURL := "https://go.example.com/foo"
if req.URL.String() != outURL {
t.Errorf("makeRequest(%v) URL = %v, want %v", inPath, req.URL, outURL)
}
// test that default user-agent is attached to the request
userAgent := req.Header.Get("User-Agent")
if client.UserAgent != userAgent {
t.Errorf("makeRequest() User-Agent = %v, want %v", userAgent, client.UserAgent)
}
}