(t *testing.T)
| 478 | } |
| 479 | |
| 480 | func TestLoginNonInteractive(t *testing.T) { |
| 481 | t.Run("no prior credentials", func(t *testing.T) { |
| 482 | testCases := []struct { |
| 483 | doc string |
| 484 | username bool |
| 485 | password bool |
| 486 | expectedErr string |
| 487 | }{ |
| 488 | { |
| 489 | doc: "success - w/ user w/ password", |
| 490 | username: true, |
| 491 | password: true, |
| 492 | }, |
| 493 | { |
| 494 | doc: "error - w/o user w/o pass ", |
| 495 | username: false, |
| 496 | password: false, |
| 497 | expectedErr: "error: cannot perform an interactive login from a non-TTY device", |
| 498 | }, |
| 499 | { |
| 500 | doc: "error - w/ user w/o pass", |
| 501 | username: true, |
| 502 | password: false, |
| 503 | expectedErr: "error: cannot perform an interactive login from a non-TTY device", |
| 504 | }, |
| 505 | { |
| 506 | doc: "error - w/o user w/ pass", |
| 507 | username: false, |
| 508 | password: true, |
| 509 | expectedErr: "error: cannot perform an interactive login from a non-TTY device", |
| 510 | }, |
| 511 | } |
| 512 | |
| 513 | // "" meaning default registry |
| 514 | registries := []string{"", "my-registry.com"} |
| 515 | |
| 516 | for _, registryAddr := range registries { |
| 517 | for _, tc := range testCases { |
| 518 | t.Run(tc.doc, func(t *testing.T) { |
| 519 | tmpDir := t.TempDir() |
| 520 | cfg := configfile.New(filepath.Join(tmpDir, "config.json")) |
| 521 | cli := test.NewFakeCli(&fakeClient{}) |
| 522 | cli.SetConfigFile(cfg) |
| 523 | options := loginOptions{ |
| 524 | serverAddress: registryAddr, |
| 525 | } |
| 526 | if tc.username { |
| 527 | options.user = "my-username" |
| 528 | } |
| 529 | if tc.password { |
| 530 | options.password = "my-password" |
| 531 | } |
| 532 | |
| 533 | loginErr := runLogin(context.Background(), cli, options) |
| 534 | if tc.expectedErr != "" { |
| 535 | assert.Error(t, loginErr, tc.expectedErr) |
| 536 | return |
| 537 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…