-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclient_test.go
More file actions
55 lines (45 loc) · 1.26 KB
/
Copy pathclient_test.go
File metadata and controls
55 lines (45 loc) · 1.26 KB
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 listennotes_test
import (
"errors"
"fmt"
"net"
"net/http"
"testing"
listennotes "github.com/ListenNotes/podcast-api-go"
)
func TestMockURL(t *testing.T) {
noDial := fmt.Errorf("no-dial")
httpClient := &http.Client{
Transport: &http.Transport{
Dial: func(network, addr string) (net.Conn, error) {
if addr != "listen-api-test.listennotes.com:443" {
t.Errorf("custom baseURL was not used: %s", addr)
}
return nil, noDial
},
},
}
client := listennotes.NewClient("", listennotes.WithHTTPClient(httpClient))
_, err := client.Search(map[string]string{"q": "a"})
if !errors.Is(err, noDial) {
t.Errorf("mock http client failure was not as expected: %s", err)
}
}
func TestProductionURL(t *testing.T) {
noDial := fmt.Errorf("no-dial")
httpClient := &http.Client{
Transport: &http.Transport{
Dial: func(network, addr string) (net.Conn, error) {
if addr != "listen-api.listennotes.com:443" {
t.Errorf("custom baseURL was not used: %s", addr)
}
return nil, noDial
},
},
}
client := listennotes.NewClient("anapikey", listennotes.WithHTTPClient(httpClient))
_, err := client.Search(map[string]string{"q": "a"})
if !errors.Is(err, noDial) {
t.Errorf("mock http client failure was not as expected: %s", err)
}
}