This repository has been archived by the owner on Jan 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_test.go
237 lines (212 loc) · 4.55 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
package databricks
import (
"bytes"
"fmt"
"io"
"net/http"
"testing"
)
// nopCloser is a struct for converting a io.Reader to an io.ReadCloser.
type nopCloser struct {
io.Reader
}
func (nopCloser) Close() error { return io.EOF }
// ErrExpected is an expected error.
var ErrExpected = fmt.Errorf("Expected")
// tripper is a http.RoundTripper that will return the error
// code it is configured with.
type tripper struct {
code int
}
// RoundTrip implements the http.RoundTripper interface.
func (t tripper) RoundTrip(
req *http.Request,
) (*http.Response, error) {
return &http.Response{
StatusCode: t.code,
Body: nopCloser{
bytes.NewBuffer(
[]byte("{'error':'expected'}"),
),
},
}, nil
}
func injectedHTTPClient(res http.Response) *http.Client {
return &http.Client{
Transport: &injectedTripper{
res: res,
},
}
}
// Non200HTTPClient is used for testing non 200 responses
// from a HTTP client.
var Non200HTTPClient = &http.Client{
Transport: &tripper{418},
}
// injectedTripper is used to return expected HTTP responses.
type injectedTripper struct {
res http.Response
}
// RoundTrip implements the http.RoundTripper interface.
func (t injectedTripper) RoundTrip(
req *http.Request,
) (*http.Response, error) {
return &t.res, nil
}
// errTripper is used to return expected HTTP transport
// errors.
type errTripper struct{}
// RoundTrip implements the http.RoundTripper interface.
func (t errTripper) RoundTrip(
req *http.Request,
) (*http.Response, error) {
return nil, ErrExpected
}
// BadTransportHTTPClient returns an ErrExpected during transport.
var BadTransportHTTPClient = &http.Client{
Transport: errTripper{},
}
// ErrOpt is an option that returns an ErrExpected.
func ErrOpt(client *Client) error {
return ErrExpected
}
func Test_Client(t *testing.T) {
t.Parallel()
client, err := NewClient("test-account", ClientHTTPClient(Non200HTTPClient))
if err != nil {
t.Fatal(err)
}
if client == nil {
t.Fatalf("NewClient returned nil")
}
client, err = NewClient("test-account", ErrOpt)
if err == nil {
t.Fatalf("Failed to get expected error: ErrExpected")
}
}
func Test_Client_Cluster(t *testing.T) {
t.Parallel()
client, err := NewClient("test-account")
if err != nil {
t.Fatal(err)
}
if client == nil {
t.Fatalf("NewClient returned nil")
}
cluster := client.Cluster()
if cluster == nil {
t.Fatalf("Cluster returned nil")
}
}
func Test_Client_DBFS(t *testing.T) {
t.Parallel()
client, err := NewClient("test-account")
if err != nil {
t.Fatal(err)
}
if client == nil {
t.Fatalf("NewClient returned nil")
}
dbfs := client.DBFS()
if dbfs == nil {
t.Fatalf("DBFS returned nil")
}
}
func Test_Client_Groups(t *testing.T) {
t.Parallel()
client, err := NewClient("test-account")
if err != nil {
t.Fatal(err)
}
if client == nil {
t.Fatalf("NewClient returned nil")
}
groups := client.Groups()
if groups == nil {
t.Fatalf("Groups returned nil")
}
}
func Test_Client_Jobs(t *testing.T) {
t.Parallel()
client, err := NewClient("test-account")
if err != nil {
t.Fatal(err)
}
if client == nil {
t.Fatalf("NewClient returned nil")
}
jobs := client.Jobs()
if jobs == nil {
t.Fatalf("Jobs returned nil")
}
}
func Test_Client_Libraries(t *testing.T) {
t.Parallel()
client, err := NewClient("test-account")
if err != nil {
t.Fatal(err)
}
if client == nil {
t.Fatalf("NewClient returned nil")
}
libraries := client.Libraries()
if libraries == nil {
t.Fatalf("Libraries returned nil")
}
}
func Test_Client_Profiles(t *testing.T) {
t.Parallel()
client, err := NewClient("test-account")
if err != nil {
t.Fatal(err)
}
if client == nil {
t.Fatalf("NewClient returned nil")
}
profiles := client.Profiles()
if profiles == nil {
t.Fatalf("Profiles returned nil")
}
}
func Test_Client_Secrets(t *testing.T) {
t.Parallel()
client, err := NewClient("test-account")
if err != nil {
t.Fatal(err)
}
if client == nil {
t.Fatalf("NewClient returned nil")
}
secrets := client.Secrets()
if secrets == nil {
t.Fatalf("Secrets returned nil")
}
}
func Test_Client_Token(t *testing.T) {
t.Parallel()
client, err := NewClient("test-account")
if err != nil {
t.Fatal(err)
}
if client == nil {
t.Fatalf("NewClient returned nil")
}
token := client.Token()
if token == nil {
t.Fatalf("Token returned nil")
}
}
func Test_Client_Workspace(t *testing.T) {
t.Parallel()
client, err := NewClient("test-account")
if err != nil {
t.Fatal(err)
}
if client == nil {
t.Fatalf("NewClient returned nil")
}
workspace := client.Workspace()
if workspace == nil {
t.Fatalf("Workspace returned nil")
}
}