Documentation
¶
Overview ¶
Package testcli provides helpers for verb-package unit tests. Mirrors the stdlib split (httptest, iotest) — production code in internal/cli, test scaffolding here, so the cli package itself stays free of test-only types.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FailingIO ¶
FailingIO returns a cli.IO whose Stdout always fails writes. Stdin is an empty reader, Stderr is a fresh bytes.Buffer, Env returns "" for every key, and Now returns the same fixed epoch as NewIO so tests that assert on time-derived output stay deterministic regardless of which constructor they picked. Shared across verb tests that need to surface the write-error branch — duplicating the literal at each call site was noise.
func NewIO ¶
NewIO returns a cli.IO wired to in-memory buffers so verb tests can assert on stdout/stderr without touching real file descriptors. Stdin defaults to an empty reader when nil — most tests don't exercise stdin. Env returns "" for every key, Now returns a fixed epoch so time-dependent assertions stay deterministic.
func RecordUnary ¶
func RecordUnary( lastPath *string, lastRawReq *[]byte, inner func(ctx context.Context, path string, req, resp any) error, ) func(ctx context.Context, path string, req, resp any) error
RecordUnary returns a Unary-shaped closure that records each invocation's path and marshaled request into the supplied pointers, then delegates to inner when non-nil. Collapses the duplicated "capture path + request bytes, then maybe call the test-supplied handler" wiring every verb package's fakeDeps wrote by hand. A marshaling failure is silently ignored so tests exercising malformed requests still reach inner's assertions.
Types ¶
type FailingWriter ¶
type FailingWriter struct{}
FailingWriter is an io.Writer that always returns an error. Verb tests use it as a Stdout to exercise write/flush error branches (tabwriter.Flush, encoder.Encode) without relying on platform-specific file state.