Documentation ¶
Overview ¶
Package prompt allows testing of "prompting" that simulates asking the user for input using stdin and stdout.
Index ¶
- func DialogTest(ctx context.Context, tb testing.TB, steps []DialogStep, cmd cli.Command, ...) error
- func DialogTestFunc(ctx context.Context, tb testing.TB, steps []DialogStep, f func(input.Prompter))
- func ReadWithTimeout(tb testing.TB, r io.Reader, wantSubstr string)
- func WriteWithTimeout(tb testing.TB, w io.Writer, msg string)
- type DialogStep
- type FakePrompter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DialogTest ¶
func DialogTest(ctx context.Context, tb testing.TB, steps []DialogStep, cmd cli.Command, runArgs []string) error
DialogTest is a helper for running tests against a CLI command that involve communicating over stdin and stdout. The expected conversation is defined as a sequence of DialogSteps.
If the observed dialog doesn't match the expected dialog, or if the test times out, then tb.Fatalf() will be called. In either of these cases, a goroutine could be leaked, but we consider that OK, because this is just a test.
cmd.Run() will be called with runArgs. If Run() returns an error, that error will be returned from this function. That is the only error that will ever be returned by this function.
If *both* (1) cmd.Run() returns error and (2) the observed dialog doesn't match the expected dialog, then tb.Fatalf() will be called (so no error will be returned. This allows the dialog to be verified even for cases that return error.
func DialogTestFunc ¶
DialogTestFunc is like DialogTest except it doesn't depend on having a cli.Command. A background goroutine is started that will execute the back-and-forth conversation defined in the given steps, simulating the user. Your provided callback should prompt the user for some input using the provided Prompter.
func ReadWithTimeout ¶
ReadWithTimeout does a single read from the given reader. It calls Fatal if that read fails or the returned string doesn't contain wantSubStr. May leak a goroutine on timeout.
Types ¶
type DialogStep ¶
DialogStep describes the prompt and respond msg.
type FakePrompter ¶
type FakePrompter struct {
// contains filtered or unexported fields
}
func (*FakePrompter) IsTestFake ¶
func (f *FakePrompter) IsTestFake()
This function doesn't do anything and is never called. It just satisfies an interface so a type assertion can check for a fake prompter.
func (*FakePrompter) Stdin ¶
func (f *FakePrompter) Stdin() io.Reader