MCPcopy Index your code
hub / github.com/cli/cli / TestRunFormTranslatesErrUserAborted

Function TestRunFormTranslatesErrUserAborted

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

Source from the content-addressed store, hash-verified

666}
667
668func TestRunFormTranslatesErrUserAborted(t *testing.T) {
669 p := newTestHuhPrompter()
670 form, _ := p.buildSelectForm("Pick one:", "", []string{"a", "b", "c"})
671
672 r, w := io.Pipe()
673 form.WithInput(r).WithOutput(io.Discard).WithWidth(80)
674
675 errCh := make(chan error, 1)
676 go func() { errCh <- p.runForm(form) }()
677
678 // Send Ctrl+C to trigger huh.ErrUserAborted
679 _, err := w.Write([]byte{0x03})
680 require.NoError(t, err)
681
682 select {
683 case err := <-errCh:
684 assert.ErrorIs(t, err, terminal.InterruptErr, "expected huh.ErrUserAborted to be translated to terminal.InterruptErr")
685 case <-time.After(5 * time.Second):
686 t.Fatal("runForm did not complete in time")
687 }
688}

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