-
Notifications
You must be signed in to change notification settings - Fork 2
/
client_logger_test.go
82 lines (74 loc) · 1.6 KB
/
client_logger_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package radarr
import (
"net/http"
"reflect"
"testing"
)
type dummyHTTPTransport struct {
http.RoundTripper
}
// RoundTrip mocked default HTTP client transport RoundTrip function
func (r *dummyHTTPTransport) RoundTrip(req *http.Request) (*http.Response, error) {
return nil, nil
}
func Test_newTransport(t *testing.T) {
type args struct {
verbose bool
key string
}
tests := []struct {
name string
want *transport
args args
}{
{
name: "Constructor",
want: &transport{transport: http.DefaultTransport, apiKey: "foo", verbose: false},
args: args{verbose: false, key: "foo"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := newTransport(tt.args.key, tt.args.verbose); !reflect.DeepEqual(got, tt.want) {
t.Errorf("newTransport() = %v, want %v", got, tt.want)
}
})
}
}
func Test_transport_RoundTrip(t *testing.T) {
req := &http.Request{Header: http.Header{}}
tests := []struct {
name string
req *http.Request
want string
}{
{
name: "X-Api-Key",
req: req,
want: "foo",
},
{
name: "Content-Type",
req: req,
want: "application/json; charset=utf-8",
},
{
name: "User-Agent",
req: req,
want: "SkYNewZ-Go-http-client/1.1",
},
}
// Fake transport to avoid the real HTTP request
trans := transport{
transport: &dummyHTTPTransport{},
apiKey: "foo",
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, _ = trans.RoundTrip(tt.req)
if req.Header.Get(tt.name) != tt.want {
t.Errorf("transport.RoundTrip() = %s, want %v", req.Header.Get(tt.name), tt.want)
}
})
}
}