I have a function in Golang something like this:
func Exit(code int) {
...
...
...
keyboard.Open()
defer keyboard.Close()
keyboard.GetKey()
PrintAndLogInfo("
Bye.")
os.Exit(code)
}
I am using the following library to use this keyboard feature
github.com/eiannone/keyboard
I would like to write unit tests for this function. However, the keyboard.GetKey() expects a key pressed. And maybe because of that when I run my test that calls the function Exit
, it fails with the error:
panic: function GetKey() should be called after Open() [recovered] panic: function GetKey() should be called after Open()
Do I need to mock something here in order to fix this error? Any ideas?