@@ -332,44 +332,93 @@ func Test_getRemoteConfig(t *testing.T) {
332
332
urlSchema string
333
333
}
334
334
tests := []struct {
335
- name string
336
- args args
337
- want * core.Remote
335
+ name string
336
+ args args
337
+ want * core.Remote
338
+ wantErr assert.ErrorAssertionFunc
339
+ setEnv func (t * testing.T )
338
340
}{
339
341
{
340
- name : "test default url schema" ,
341
- args : args {endpoint : "https://example.com/" , urlSchema : "default" },
342
- want : & core.Remote {Endpoint : "https://example.com" , URLSchema : "default" , CacheDir : "/tmp" },
342
+ name : "test default url schema" ,
343
+ args : args {endpoint : "https://example.com/" , urlSchema : "default" },
344
+ want : & core.Remote {Endpoint : "https://example.com" , URLSchema : "default" , CacheDir : "/tmp" },
345
+ wantErr : assert .NoError ,
343
346
},
344
347
{
345
- name : "test default url schema with 'dogus' suffix" ,
346
- args : args {endpoint : "https://example.com/dogus" , urlSchema : "default" },
347
- want : & core.Remote {Endpoint : "https://example.com" , URLSchema : "default" , CacheDir : "/tmp" },
348
+ name : "test default url schema with 'dogus' suffix" ,
349
+ args : args {endpoint : "https://example.com/dogus" , urlSchema : "default" },
350
+ want : & core.Remote {Endpoint : "https://example.com" , URLSchema : "default" , CacheDir : "/tmp" },
351
+ wantErr : assert .NoError ,
348
352
},
349
353
{
350
- name : "test default url schema with 'dogus/' suffix" ,
351
- args : args {endpoint : "https://example.com/dogus/" , urlSchema : "default" },
352
- want : & core.Remote {Endpoint : "https://example.com" , URLSchema : "default" , CacheDir : "/tmp" },
354
+ name : "test default url schema with 'dogus/' suffix" ,
355
+ args : args {endpoint : "https://example.com/dogus/" , urlSchema : "default" },
356
+ want : & core.Remote {Endpoint : "https://example.com" , URLSchema : "default" , CacheDir : "/tmp" },
357
+ wantErr : assert .NoError ,
353
358
},
354
359
{
355
- name : "test non-default url schema" ,
356
- args : args {endpoint : "https://example.com/" , urlSchema : "index" },
357
- want : & core.Remote {Endpoint : "https://example.com" , URLSchema : "index" , CacheDir : "/tmp" },
360
+ name : "test non-default url schema" ,
361
+ args : args {endpoint : "https://example.com/" , urlSchema : "index" },
362
+ want : & core.Remote {Endpoint : "https://example.com" , URLSchema : "index" , CacheDir : "/tmp" },
363
+ wantErr : assert .NoError ,
358
364
},
359
365
{
360
- name : "test non-default url schema with 'dogus' suffix" ,
361
- args : args {endpoint : "https://example.com/dogus" , urlSchema : "index" },
362
- want : & core.Remote {Endpoint : "https://example.com/dogus" , URLSchema : "index" , CacheDir : "/tmp" },
366
+ name : "test non-default url schema with 'dogus' suffix" ,
367
+ args : args {endpoint : "https://example.com/dogus" , urlSchema : "index" },
368
+ want : & core.Remote {Endpoint : "https://example.com/dogus" , URLSchema : "index" , CacheDir : "/tmp" },
369
+ wantErr : assert .NoError ,
363
370
},
364
371
{
365
- name : "test non-default url schema with 'dogus/' suffix" ,
372
+ name : "test non-default url schema with 'dogus/' suffix" ,
373
+ args : args {endpoint : "https://example.com/dogus/" , urlSchema : "index" },
374
+ want : & core.Remote {Endpoint : "https://example.com/dogus" , URLSchema : "index" , CacheDir : "/tmp" },
375
+ wantErr : assert .NoError ,
376
+ },
377
+ {
378
+ name : "test with proxy" ,
366
379
args : args {endpoint : "https://example.com/dogus/" , urlSchema : "index" },
367
- want : & core.Remote {Endpoint : "https://example.com/dogus" , URLSchema : "index" , CacheDir : "/tmp" },
380
+ want : & core.Remote {Endpoint : "https://example.com/dogus" , URLSchema : "index" , CacheDir : "/tmp" , ProxySettings : core.ProxySettings {
381
+ Enabled : true ,
382
+ Server : "host" ,
383
+ Port : 3128 ,
384
+ Username : "user" ,
385
+ Password : "password" ,
386
+ }},
387
+ wantErr : assert .NoError ,
388
+ setEnv : func (t * testing.T ) {
389
+ t .Setenv ("PROXY_URL" , "https://user:password@host:3128" )
390
+ },
391
+ },
392
+ {
393
+ name : "test proxy invalid url" ,
394
+ args : args {endpoint : "https://example.com/dogus/" , urlSchema : "index" },
395
+ want : nil ,
396
+ wantErr : assert .Error ,
397
+ setEnv : func (t * testing.T ) {
398
+ t .Setenv ("PROXY_URL" , "://f" )
399
+ },
400
+ },
401
+ {
402
+ name : "test proxy invalid port" ,
403
+ args : args {endpoint : "https://example.com/dogus/" , urlSchema : "index" },
404
+ want : nil ,
405
+ wantErr : assert .Error ,
406
+ setEnv : func (t * testing.T ) {
407
+ t .Setenv ("PROXY_URL" , "https://user:password@host:invalid" )
408
+ },
368
409
},
369
410
}
370
411
for _ , tt := range tests {
371
412
t .Run (tt .name , func (t * testing.T ) {
372
- assert .Equalf (t , tt .want , getRemoteConfig (tt .args .endpoint , tt .args .urlSchema ), "getRemoteConfig(%v, %v)" , tt .args .endpoint , tt .args .urlSchema )
413
+ if tt .setEnv != nil {
414
+ tt .setEnv (t )
415
+ }
416
+
417
+ config , err := getRemoteConfig (tt .args .endpoint , tt .args .urlSchema )
418
+
419
+ tt .wantErr (t , err )
420
+
421
+ assert .Equalf (t , tt .want , config , "getRemoteConfig(%v, %v)" , tt .args .endpoint , tt .args .urlSchema )
373
422
})
374
423
}
375
424
}
0 commit comments