-
Notifications
You must be signed in to change notification settings - Fork 1
/
client_test.go
98 lines (87 loc) · 2.23 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package modzy
import (
"net/http"
"testing"
)
func TestClientWithAPIKey(t *testing.T) {
c := (&standardClient{
requestor: &requestor{},
})
c.WithAPIKey("k")
req := &http.Request{
Header: http.Header{},
}
decorated := c.requestor.authorizationDecorator(req)
got := decorated.Header.Get("Authorization")
if got != "ApiKey k" {
t.Errorf("Expected ApiKey k, got %s", got)
}
}
func TestClientWithWithTeamKey(t *testing.T) {
c := (&standardClient{
requestor: &requestor{},
})
c.WithTeamKey("team", "teamKey")
req := &http.Request{
Header: http.Header{},
}
decorated := c.requestor.authorizationDecorator(req)
if decorated.Header.Get("Authorization") != "Bearer teamKey" {
t.Errorf("Expected Bearer teamKey, got %s", decorated.Header.Get("Authorization"))
}
if decorated.Header.Get("Modzy-Team-Id") != "team" {
t.Errorf("Expected team, got %s", decorated.Header.Get("Modzy-Team-Id"))
}
}
func TestClientWithOptions(t *testing.T) {
c := (&standardClient{
requestor: &requestor{},
})
c.WithOptions(WithHTTPDebugging(true, false))
if c.requestor.requestDebugging != true {
t.Errorf("Expected requestDebugging to be true, was not")
}
}
func TestNewClient(t *testing.T) {
c := NewClient("baseURL", WithHTTPDebugging(true, false))
standardC := c.(*standardClient)
if standardC.requestor.baseURL != "baseURL" {
t.Errorf("baseURL not set")
}
if standardC.requestor.httpClient != defaultHTTPClient {
t.Errorf("default httpClient not set")
}
if standardC.jobsClient == nil {
t.Errorf("no jobs client")
}
if standardC.modelsClient == nil {
t.Errorf("no models client")
}
}
func TestClientJobs(t *testing.T) {
jobsClient := &standardJobsClient{}
c := (&standardClient{
jobsClient: jobsClient,
})
if c.Jobs() != jobsClient {
t.Errorf("jobsClient did not return")
}
}
func TestClientModels(t *testing.T) {
modelsClient := &standardModelsClient{}
c := (&standardClient{
modelsClient: modelsClient,
})
if c.Models() != modelsClient {
t.Errorf("modelsClient did not return")
}
}
func TestClientDashboard(t *testing.T) {
dashboardClient := &standardDashboardClient{}
c := (&standardClient{
dashboardClient: dashboardClient,
})
if c.Dashboard() != dashboardClient {
t.Errorf("dashboardClient did not return")
}
}