MCPcopy
hub / github.com/cli/cli / TestRunFormTranslatesErrUserAborted

Function TestRunFormTranslatesErrUserAborted

internal/prompter/huh_prompter_test.go:623–643  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

621}
622
623func TestRunFormTranslatesErrUserAborted(t *testing.T) {
624 p := newTestHuhPrompter()
625 form, _ := p.buildSelectForm("Pick one:", "", []string{"a", "b", "c"})
626
627 r, w := io.Pipe()
628 form.WithInput(r).WithOutput(io.Discard).WithWidth(80)
629
630 errCh := make(chan error, 1)
631 go func() { errCh <- p.runForm(form) }()
632
633 // Send Ctrl+C to trigger huh.ErrUserAborted
634 _, err := w.Write([]byte{0x03})
635 require.NoError(t, err)
636
637 select {
638 case err := <-errCh:
639 assert.ErrorIs(t, err, terminal.InterruptErr, "expected huh.ErrUserAborted to be translated to terminal.InterruptErr")
640 case <-time.After(5 * time.Second):
641 t.Fatal("runForm did not complete in time")
642 }
643}

Callers

nothing calls this directly

Calls 5

newTestHuhPrompterFunction · 0.85
buildSelectFormMethod · 0.80
WithWidthMethod · 0.80
runFormMethod · 0.80
WriteMethod · 0.65

Tested by

no test coverage detected