-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_test.go
More file actions
57 lines (50 loc) · 1008 Bytes
/
Copy pathclient_test.go
File metadata and controls
57 lines (50 loc) · 1008 Bytes
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
package spotifyprivateapi
import (
"io"
"net/http"
"strings"
"testing"
)
type mockHTTPClient struct {
doFunc func(req *http.Request) (*http.Response, error)
}
func (m *mockHTTPClient) Do(req *http.Request) (*http.Response, error) {
return m.doFunc(req)
}
func mockResponse(statusCode int, body string) *http.Response {
return &http.Response{
StatusCode: statusCode,
Body: io.NopCloser(strings.NewReader(body)),
Header: make(http.Header),
}
}
func newTestClient(httpClient *mockHTTPClient) *Client {
return NewClient(
WithHTTPDoer(httpClient),
WithDebug(false),
WithLogger(nil),
)
}
func TestNewClient(t *testing.T) {
tests := []struct {
name string
opts []Option
}{
{
name: "default client",
opts: nil,
},
{
name: "with debug",
opts: []Option{WithDebug(true)},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
client := NewClient(tt.opts...)
if client == nil {
t.Error("NewClient returned nil")
}
})
}
}