Faking stdin and stdout in Go

2 · Eli Bendersky · May 2, 2020, 12:40 p.m.
In this post I want to discuss faking (or redirecting) standard input and output (os.Stdin and os.Stdout [1]) in Go programs. This is often done in tests, but may also be useful in other scenarios. The basic idea is demonstrated in the following pseudocode: StartFakingIO(stdin to feed …...