@@ -70,8 +70,8 @@ func copyToTempFile(t *testing.T, pattern string, filename string) (file *os.Fil
70
70
71
71
func TestNewClient (t * testing.T ) {
72
72
const (
73
- pwd1 = "password"
74
- token = "token"
73
+ pwd1 = "password"
74
+ token = "token"
75
75
serverCert = "../../config/tlscfg/testdata/example-server-cert.pem"
76
76
)
77
77
pwdFile := filepath .Join (t .TempDir (), "pwd" )
@@ -81,7 +81,6 @@ func TestNewClient(t *testing.T) {
81
81
// copy certs to temp so we can modify them
82
82
certFilePath := copyToTempFile (t , "cert.crt" , serverCert )
83
83
84
-
85
84
testServer := httptest .NewServer (http .HandlerFunc (func (res http.ResponseWriter , req * http.Request ) {
86
85
require .Equal (t , http .MethodGet , req .Method )
87
86
res .WriteHeader (http .StatusOK )
@@ -108,7 +107,7 @@ func TestNewClient(t *testing.T) {
108
107
defer testServer8 .Close ()
109
108
tests := []struct {
110
109
name string
111
- config * Configuration
110
+ config * Configuration
112
111
expectedError bool
113
112
}{
114
113
{
@@ -128,164 +127,164 @@ func TestNewClient(t *testing.T) {
128
127
{
129
128
name : "success with valid configuration and tls enabled" ,
130
129
config : & Configuration {
131
- Servers : []string {testServer .URL },
132
- AllowTokenFromContext : true ,
133
- Password : "secret" ,
134
- LogLevel : "debug" ,
135
- Username : "user" ,
136
- PasswordFilePath : "" ,
137
- BulkSize : - 1 , // disable bulk; we want immediate flush
138
- Version : 8 ,
139
- TLS : tlscfg.Options {Enabled : true },
140
- },
130
+ Servers : []string {testServer .URL },
131
+ AllowTokenFromContext : true ,
132
+ Password : "secret" ,
133
+ LogLevel : "debug" ,
134
+ Username : "user" ,
135
+ PasswordFilePath : "" ,
136
+ BulkSize : - 1 , // disable bulk; we want immediate flush
137
+ Version : 8 ,
138
+ TLS : tlscfg.Options {Enabled : true },
139
+ },
141
140
expectedError : false ,
142
141
},
143
142
{
144
143
name : "success with valid configuration and reading token and certicate from file" ,
145
144
config : & Configuration {
146
- Servers : []string {testServer .URL },
147
- AllowTokenFromContext : true ,
148
- Password : "secret" ,
149
- LogLevel : "debug" ,
150
- Username : "user" ,
151
- PasswordFilePath : "" ,
152
- BulkSize : - 1 , // disable bulk; we want immediate flush
153
- Version : 1 ,
154
- TLS : tlscfg.Options {Enabled : false , CAPath : certFilePath .Name ()},
155
- TokenFilePath : pwdtokenFile ,
156
- },
145
+ Servers : []string {testServer .URL },
146
+ AllowTokenFromContext : true ,
147
+ Password : "secret" ,
148
+ LogLevel : "debug" ,
149
+ Username : "user" ,
150
+ PasswordFilePath : "" ,
151
+ BulkSize : - 1 , // disable bulk; we want immediate flush
152
+ Version : 1 ,
153
+ TLS : tlscfg.Options {Enabled : false , CAPath : certFilePath .Name ()},
154
+ TokenFilePath : pwdtokenFile ,
155
+ },
157
156
expectedError : false ,
158
157
},
159
158
{
160
159
name : "succes with invalid configuration of version higher than 8" ,
161
160
config : & Configuration {
162
- Servers : []string {testServer8 .URL },
163
- AllowTokenFromContext : true ,
164
- Password : "secret" ,
165
- LogLevel : "debug" ,
166
- Username : "user" ,
167
- PasswordFilePath : "" ,
168
- BulkSize : - 1 , // disable bulk; we want immediate flush
169
- Version : 9 ,
170
- },
161
+ Servers : []string {testServer8 .URL },
162
+ AllowTokenFromContext : true ,
163
+ Password : "secret" ,
164
+ LogLevel : "debug" ,
165
+ Username : "user" ,
166
+ PasswordFilePath : "" ,
167
+ BulkSize : - 1 , // disable bulk; we want immediate flush
168
+ Version : 9 ,
169
+ },
171
170
expectedError : false ,
172
171
},
173
172
{
174
173
name : "success with valid configuration with version 1" ,
175
174
config : & Configuration {
176
- Servers : []string {testServer1 .URL },
177
- AllowTokenFromContext : true ,
178
- Password : "secret" ,
179
- LogLevel : "debug" ,
180
- Username : "user" ,
181
- PasswordFilePath : "" ,
182
- BulkSize : - 1 , // disable bulk; we want immediate flush
183
- },
175
+ Servers : []string {testServer1 .URL },
176
+ AllowTokenFromContext : true ,
177
+ Password : "secret" ,
178
+ LogLevel : "debug" ,
179
+ Username : "user" ,
180
+ PasswordFilePath : "" ,
181
+ BulkSize : - 1 , // disable bulk; we want immediate flush
182
+ },
184
183
expectedError : false ,
185
184
},
186
185
{
187
186
name : "success with valid configuration with version 2" ,
188
187
config : & Configuration {
189
- Servers : []string {testServer2 .URL },
190
- AllowTokenFromContext : true ,
191
- Password : "secret" ,
192
- LogLevel : "debug" ,
193
- Username : "user" ,
194
- PasswordFilePath : "" ,
195
- BulkSize : - 1 , // disable bulk; we want immediate flush
196
- },
188
+ Servers : []string {testServer2 .URL },
189
+ AllowTokenFromContext : true ,
190
+ Password : "secret" ,
191
+ LogLevel : "debug" ,
192
+ Username : "user" ,
193
+ PasswordFilePath : "" ,
194
+ BulkSize : - 1 , // disable bulk; we want immediate flush
195
+ },
197
196
expectedError : false ,
198
197
},
199
198
{
200
199
name : "success with valid configuration password from file" ,
201
200
config : & Configuration {
202
- Servers : []string {testServer .URL },
203
- AllowTokenFromContext : true ,
204
- Password : "" ,
205
- LogLevel : "debug" ,
206
- Username : "user" ,
207
- PasswordFilePath : pwdFile ,
208
- BulkSize : - 1 , // disable bulk; we want immediate flush
209
- },
201
+ Servers : []string {testServer .URL },
202
+ AllowTokenFromContext : true ,
203
+ Password : "" ,
204
+ LogLevel : "debug" ,
205
+ Username : "user" ,
206
+ PasswordFilePath : pwdFile ,
207
+ BulkSize : - 1 , // disable bulk; we want immediate flush
208
+ },
210
209
expectedError : false ,
211
210
},
212
211
{
213
212
name : "fali with configuration password and password from file are set" ,
214
213
config : & Configuration {
215
- Servers : []string {testServer .URL },
216
- AllowTokenFromContext : true ,
217
- Password : "secret" ,
218
- LogLevel : "debug" ,
219
- Username : "user" ,
220
- PasswordFilePath : pwdFile ,
221
- BulkSize : - 1 , // disable bulk; we want immediate flush
222
- },
214
+ Servers : []string {testServer .URL },
215
+ AllowTokenFromContext : true ,
216
+ Password : "secret" ,
217
+ LogLevel : "debug" ,
218
+ Username : "user" ,
219
+ PasswordFilePath : pwdFile ,
220
+ BulkSize : - 1 , // disable bulk; we want immediate flush
221
+ },
223
222
expectedError : true ,
224
223
},
225
224
{
226
225
name : "fail with missing server" ,
227
226
config : & Configuration {
228
- Servers : []string {},
229
- AllowTokenFromContext : true ,
230
- Password : "secret" ,
231
- LogLevel : "debug" ,
232
- Username : "user" ,
233
- PasswordFilePath : "" ,
234
- BulkSize : - 1 , // disable bulk; we want immediate flush
235
- },
227
+ Servers : []string {},
228
+ AllowTokenFromContext : true ,
229
+ Password : "secret" ,
230
+ LogLevel : "debug" ,
231
+ Username : "user" ,
232
+ PasswordFilePath : "" ,
233
+ BulkSize : - 1 , // disable bulk; we want immediate flush
234
+ },
236
235
expectedError : true ,
237
236
},
238
237
{
239
238
name : "fail with invalid configuration invalid loglevel" ,
240
239
config : & Configuration {
241
- Servers : []string {testServer .URL },
242
- AllowTokenFromContext : true ,
243
- Password : "secret" ,
244
- LogLevel : "invalid" ,
245
- Username : "user" ,
246
- PasswordFilePath : "" ,
247
- BulkSize : - 1 , // disable bulk; we want immediate flush
248
- },
240
+ Servers : []string {testServer .URL },
241
+ AllowTokenFromContext : true ,
242
+ Password : "secret" ,
243
+ LogLevel : "invalid" ,
244
+ Username : "user" ,
245
+ PasswordFilePath : "" ,
246
+ BulkSize : - 1 , // disable bulk; we want immediate flush
247
+ },
249
248
expectedError : true ,
250
249
},
251
250
{
252
251
name : "fail with invalid configuration invalid bulkworkers number" ,
253
252
config : & Configuration {
254
- Servers : []string {testServer .URL },
255
- AllowTokenFromContext : true ,
256
- Password : "secret" ,
257
- LogLevel : "invalid" ,
258
- Username : "user" ,
259
- PasswordFilePath : "" ,
260
- BulkWorkers : 0 ,
261
- BulkSize : - 1 , // disable bulk; we want immediate flush
262
- },
253
+ Servers : []string {testServer .URL },
254
+ AllowTokenFromContext : true ,
255
+ Password : "secret" ,
256
+ LogLevel : "invalid" ,
257
+ Username : "user" ,
258
+ PasswordFilePath : "" ,
259
+ BulkWorkers : 0 ,
260
+ BulkSize : - 1 , // disable bulk; we want immediate flush
261
+ },
263
262
expectedError : true ,
264
263
},
265
264
{
266
265
name : "success with valid configuration and info log level" ,
267
266
config : & Configuration {
268
- Servers : []string {testServer .URL },
269
- AllowTokenFromContext : true ,
270
- Password : "secret" ,
271
- LogLevel : "info" ,
272
- Username : "user" ,
273
- PasswordFilePath : "" ,
274
- BulkSize : - 1 , // disable bulk; we want immediate flush
275
- },
267
+ Servers : []string {testServer .URL },
268
+ AllowTokenFromContext : true ,
269
+ Password : "secret" ,
270
+ LogLevel : "info" ,
271
+ Username : "user" ,
272
+ PasswordFilePath : "" ,
273
+ BulkSize : - 1 , // disable bulk; we want immediate flush
274
+ },
276
275
expectedError : false ,
277
276
},
278
277
{
279
278
name : "success with valid configuration and error log level" ,
280
279
config : & Configuration {
281
- Servers : []string {testServer .URL },
282
- AllowTokenFromContext : true ,
283
- Password : "secret" ,
284
- LogLevel : "error" ,
285
- Username : "user" ,
286
- PasswordFilePath : "" ,
287
- BulkSize : - 1 , // disable bulk; we want immediate flush
288
- },
280
+ Servers : []string {testServer .URL },
281
+ AllowTokenFromContext : true ,
282
+ Password : "secret" ,
283
+ LogLevel : "error" ,
284
+ Username : "user" ,
285
+ PasswordFilePath : "" ,
286
+ BulkSize : - 1 , // disable bulk; we want immediate flush
287
+ },
289
288
expectedError : false ,
290
289
},
291
290
}
0 commit comments