@@ -306,6 +306,85 @@ func TestInitConfig(t *testing.T) {
306
306
authChoiceMsg + "\n " + userMsg + passMsg + "\n " + formatChoiceMsg +
307
307
"\n " + "\n " + fmt .Sprintf (validCredentialsMsg , "auser" ) + finalMsg + "\n " ,
308
308
},
309
+ {
310
+ name : "doesn't find a config file and user creates a new one with user/pass, GET user fails, but deployment list succeeds" ,
311
+ args : args {params : InitConfigParams {
312
+ Viper : emptyViperToCreateConfigUserPass ,
313
+ FilePath : filepath .Join (testFiles , "newConfigUserPass" ),
314
+ Reader : io .MultiReader (
315
+ strings .NewReader ("y\n " ),
316
+ strings .NewReader ("2\n " ),
317
+ strings .NewReader ("https://ahost\n " ),
318
+ strings .NewReader ("2\n " ),
319
+ strings .NewReader ("auser\n " ),
320
+ strings .NewReader ("1\n " ),
321
+ ),
322
+ Writer : new (bytes.Buffer ),
323
+ ErrWriter : new (bytes.Buffer ),
324
+ PasswordReadFunc : func (int ) ([]byte , error ) {
325
+ return []byte ("apassword" ), nil
326
+ },
327
+ Client : mock .NewClient (
328
+ mock .New200Response (mock .NewStructBody (models.TokenResponse {
329
+ Token : ec .String ("atoken" ),
330
+ })),
331
+ mock .New404Response (mock .NewStructBody (models.User {
332
+ UserName : ec .String ("auser" ),
333
+ })),
334
+ mock .New200Response (mock .NewStructBody (models.DeploymentsListResponse {})),
335
+ ),
336
+ }},
337
+ wantSettings : map [string ]interface {}{
338
+ "host" : "https://ahost" ,
339
+ "insecure" : true ,
340
+ "output" : "text" ,
341
+ "pass" : "apassword" ,
342
+ "user" : "auser" ,
343
+ },
344
+ wantOutput : disclaimer + missingConfigMsg + hostChoiceMsg + "\n " + eceHostMsg +
345
+ authChoiceMsg + "\n " + userMsg + passMsg + "\n " + formatChoiceMsg +
346
+ "\n " + "\n " + validCredentialsAlternativeMsg + finalMsg + "\n " ,
347
+ },
348
+ {
349
+ name : "doesn't find a config file and user creates a new one with user/pass, and returns error on API test" ,
350
+ args : args {params : InitConfigParams {
351
+ Viper : emptyViperToCreateConfigUserPass ,
352
+ FilePath : filepath .Join (testFiles , "newConfigUserPass" ),
353
+ Reader : io .MultiReader (
354
+ strings .NewReader ("y\n " ),
355
+ strings .NewReader ("2\n " ),
356
+ strings .NewReader ("https://ahost\n " ),
357
+ strings .NewReader ("2\n " ),
358
+ strings .NewReader ("auser\n " ),
359
+ strings .NewReader ("1\n " ),
360
+ ),
361
+ Writer : new (bytes.Buffer ),
362
+ ErrWriter : new (bytes.Buffer ),
363
+ PasswordReadFunc : func (int ) ([]byte , error ) {
364
+ return []byte ("apassword" ), nil
365
+ },
366
+ Client : mock .NewClient (
367
+ mock .New200Response (mock .NewStructBody (models.TokenResponse {
368
+ Token : ec .String ("atoken" ),
369
+ })),
370
+ mock .New404Response (mock .NewStructBody (models.User {
371
+ UserName : ec .String ("auser" ),
372
+ })),
373
+ mock .New404Response (mock .NewStructBody (models.DeploymentsListResponse {})),
374
+ ),
375
+ }},
376
+ wantSettings : map [string ]interface {}{
377
+ "host" : "https://ahost" ,
378
+ "insecure" : true ,
379
+ "output" : "text" ,
380
+ "pass" : "apassword" ,
381
+ "user" : "auser" ,
382
+ },
383
+ err : errors .New (invalidCredentialsMsg ),
384
+ wantOutput : disclaimer + missingConfigMsg + hostChoiceMsg + "\n " + eceHostMsg +
385
+ authChoiceMsg + "\n " + userMsg + passMsg + "\n " + formatChoiceMsg +
386
+ "\n " + "\n " ,
387
+ },
309
388
{
310
389
name : "finds a config file and user changes the values" ,
311
390
args : args {params : InitConfigParams {
0 commit comments