Using Go 1.11 I have a function that prints a label above a user input. This is fine and works but when I have started to write the test for this function it prints out this label when running the tests.
I have also use log.Print
but then in the test file adding the following
func init() {
log.SetOutput(ioutil.Discard)
}
This stops the log.Print
from being displayed when running the tests. So how do I get it to do the same for any fmt.Println
?
UPDATE
I thought I would post the func that I am testing and how I set up,
func checkLoop(loopCount int) int {
var input int
var ok bool
for !ok {
fmt.Printf("Input %d :: ", loopCount)
ok, input = takeInput()
}
return input
}
So takeInput()
only takes the users input, using fmt.Scan
and checks it to see if its within a set range I want. So it returns a bool and if its false it will re-use the label to check what input number it is.