☆
3
Testing a CLI that writes to stdout without making a mess in the repo
I am writing a small Go CLI and want integration tests that capture stdout. Right now I shell out from the test, redirect to a temp file, and compare strings, which works but feels clumsy. Is there a standard pattern for injecting an io.Writer into cobra commands so tests stay in-process?
3 replies