「"golang" test "os.Stdin" "keinos"」でググってもヒットしなかったので、自分のググラビリティとして。
In the dependency injection point of view, it is a good practice to var OsStdin = os.Stdin
and use OsStdin
instead of os.Stdin
. Then monkey patch (temporary replace) the variable during the test.
But if the external package doesn't support that OsStdin
alias feature, and uses os.Stdin
, we need to mock the os.Stdin
some how.