lundi 25 juillet 2016

Mock a stdout stream for bufio.NewScanner

I want to write a test for a utility function where I use bufio.NewScanner and Scan(). I usually use it on stdout and now I want to simulate a short piece of stream where I can return some static string for the purpose of the test.

bufio.NewScanner(r io.Reader) takes a Reader but that only requires a read method. By reading the source code I couldn't figure out from which buffer it reads or how that gets passed in.

How can I mock that in a short and concise way?

Aucun commentaire:

Enregistrer un commentaire