Documentation
¶
Overview ¶
Package clitest runs a tree made with cli in a test: one call gives the exit code, stdout and stderr of a command, and Lines gives the log lines it wrote.
exit, stdout, stderr := clitest.Run(t, root, "", "messages", "search", "--format", "jsonl", "deploy")
The runner gets the test's ctx, not one from lifecycle.Run: a runner that calls lifecycle.OnStop, Stop or Go panics here (an internal failure in the result). Commands rarely need them (contract.md section 9.1); one that does is tested as lifecycle tests itself, in a child process.
Index ¶
- func Lines(t testing.TB) []map[string]any
- func Raw(t testing.TB) [][]byte
- func Run(t testing.TB, root *cobra.Command, stdin string, args ...string) (exit int, stdout, stderr string)
- func RunContext(ctx context.Context, t testing.TB, root *cobra.Command, stdin string, ...) (exit int, stdout, stderr string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Lines ¶
Lines returns every log line the test's runs wrote so far, each decoded as a JSON object, in order.
func Raw ¶
Raw returns every log line the test's runs wrote so far, as written, each with its newline; for contracttest.Check.
func Run ¶
func Run(t testing.TB, root *cobra.Command, stdin string, args ...string) (exit int, stdout, stderr string)
Run runs the tree as cli.Execute does, with stdin as the input, and returns the exit code lifecycle.Run would use with stdout and stderr. The log lines go to a buffer Lines reads, at level debug. root must come from cli.Root.
Types ¶
This section is empty.