-
Notifications
You must be signed in to change notification settings - Fork 0
/
discogs_test.go
58 lines (46 loc) · 1.05 KB
/
discogs_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
package discogs
import (
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/google/go-cmp/cmp"
)
var (
// mux is the HTTP request multiplexer used with the test server.
mux *http.ServeMux
// client is the PagerDuty client being tested.
client *Client
// server is a test HTTP server used to provide mock API responses.
server *httptest.Server
)
func setup() {
mux = http.NewServeMux()
server = httptest.NewServer(mux)
authToken := "foo"
client = NewClient(authToken)
}
func teardown() {
server.Close()
}
func testMethod(t *testing.T, r *http.Request, want string) {
t.Helper()
if got := r.Method; got != want {
t.Errorf("Request method: %v, want %v", got, want)
}
}
func testEqual(t *testing.T, want interface{}, got interface{}) {
t.Helper()
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("values not equal (-want / +got):\n%s", diff)
}
}
func defaultTestClient(serverURL, apiKey string) *Client {
return &Client{
apiKey: apiKey,
HTTPClient: &http.Client{
Timeout: 5 * time.Minute,
},
baseURL: serverURL,
}
}