-
Notifications
You must be signed in to change notification settings - Fork 2
/
client_test.go
80 lines (75 loc) · 2.58 KB
/
client_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
package radarr
import (
"net/http"
"reflect"
"testing"
"time"
)
func TestNew(t *testing.T) {
type args struct {
radarrURL string
apiKey string
client HTTPClientInterface
}
var serviceWithCustomHTTPClient *Service = &Service{url: dummyURL, client: dummyHTTPClient}
serviceWithCustomHTTPClient.Movies = newMovieService(serviceWithCustomHTTPClient)
serviceWithCustomHTTPClient.Diskspace = newDiskspaceService(serviceWithCustomHTTPClient)
serviceWithCustomHTTPClient.SystemStatus = newSystemStatusService(serviceWithCustomHTTPClient)
serviceWithCustomHTTPClient.Command = newCommandService(serviceWithCustomHTTPClient)
serviceWithCustomHTTPClient.History = newHistoryService(serviceWithCustomHTTPClient)
client := http.Client{}
client.Timeout = time.Second * 10
client.Transport = newTransport(dummyAPIKey, false)
var serviceWithDefaultHTTPClient *Service = &Service{url: dummyURL, client: &client}
serviceWithDefaultHTTPClient.Movies = newMovieService(serviceWithDefaultHTTPClient)
serviceWithDefaultHTTPClient.Diskspace = newDiskspaceService(serviceWithDefaultHTTPClient)
serviceWithDefaultHTTPClient.SystemStatus = newSystemStatusService(serviceWithDefaultHTTPClient)
serviceWithDefaultHTTPClient.Command = newCommandService(serviceWithDefaultHTTPClient)
serviceWithDefaultHTTPClient.History = newHistoryService(serviceWithDefaultHTTPClient)
tests := []struct {
name string
args args
want *Service
wantErr bool
}{
{
name: "Error because of bad URL",
args: args{apiKey: dummyAPIKey, radarrURL: "bad-url", client: dummyHTTPClient},
wantErr: true,
},
{
name: "Error because of non-provided API key",
args: args{radarrURL: dummyURL, client: dummyHTTPClient},
wantErr: true,
},
{
name: "Error because of non-provided API key",
args: args{apiKey: "", radarrURL: dummyURL, client: dummyHTTPClient},
wantErr: true,
},
{
name: "Good service",
args: args{radarrURL: dummyURL, apiKey: dummyAPIKey, client: dummyHTTPClient},
wantErr: false,
want: serviceWithCustomHTTPClient,
},
{
name: "Default HTTP Client",
args: args{radarrURL: dummyURL, apiKey: dummyAPIKey, client: nil},
wantErr: false,
want: serviceWithDefaultHTTPClient,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := New(tt.args.radarrURL, tt.args.apiKey, tt.args.client)
if (err != nil) != tt.wantErr {
t.Errorf("New() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("New() = %v, want %v", got, tt.want)
}
})
}
}