MCPcopy Create free account
hub / github.com/docker/cli / TestLoginTermination

Function TestLoginTermination

cli/command/registry/login_test.go:617–653  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

615}
616
617func 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
655func TestLoginValidateFlags(t *testing.T) {
656 for _, tc := range []struct {

Callers

nothing calls this directly

Calls 5

SetConfigFileMethod · 0.95
runLoginFunction · 0.85
SetInMethod · 0.65
CloseMethod · 0.45
SetOutMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…