I have written a code in golang which read input from the terminal and then reverse that input in an array. I want to write a test for that function. So how I write a test case for this kind of problem.
here is my code which is working
package main
import (
"bufio"
"fmt"
"os"
"strings"
"testing"
)
func main() {
s := reverse()
fmt.Println(s)
}
func Reverse() []string {
var s []string
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter text the value of array: ")
text, _ := reader.ReadString('\n')
newArray := strings.Fields(text)
for i := len(newArray) - 1; i >= 0; i-- {
s = append(s, newArray[i])
}
return s
}
here I am trying to write test function like this
func TestReverseToReturnReversedInputString(t *testing.T) {
actualResult := Reverse()
}
What here issue is my Reverse function does not take any input. I read input from terminal so any way to provide input so test case is working