(t *testing.T)
| 615 | } |
| 616 | |
| 617 | func TestLoginTermination(t *testing.T) { |
| 618 | p, tty, err := pty.Open() |
| 619 | assert.NilError(t, err) |
| 620 | |
| 621 | t.Cleanup(func() { |
| 622 | _ = tty.Close() |
| 623 | _ = p.Close() |
| 624 | }) |
| 625 | |
| 626 | tmpDir := t.TempDir() |
| 627 | cfg := configfile.New(filepath.Join(tmpDir, "config.json")) |
| 628 | cli := test.NewFakeCli(&fakeClient{}, func(fc *test.FakeCli) { |
| 629 | fc.SetOut(streams.NewOut(tty)) |
| 630 | fc.SetIn(streams.NewIn(tty)) |
| 631 | }) |
| 632 | cli.SetConfigFile(cfg) |
| 633 | |
| 634 | ctx, cancel := context.WithCancel(t.Context()) |
| 635 | t.Cleanup(cancel) |
| 636 | |
| 637 | runErr := make(chan error) |
| 638 | go func() { |
| 639 | runErr <- runLogin(ctx, cli, loginOptions{ |
| 640 | user: "test-user", |
| 641 | }) |
| 642 | }() |
| 643 | |
| 644 | // Let the prompt get canceled by the context |
| 645 | cancel() |
| 646 | |
| 647 | select { |
| 648 | case <-time.After(1 * time.Second): |
| 649 | t.Fatal("timed out after 1 second. `runLogin` did not return") |
| 650 | case err := <-runErr: |
| 651 | assert.ErrorIs(t, err, prompt.ErrTerminated) |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | func TestLoginValidateFlags(t *testing.T) { |
| 656 | for _, tc := range []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…