mock.on("FunctionName", "someStringArgument").Return(...)
Suppose if someStringArgument
is "hello" then I want to return "1". But if someStringArgument
is any other string I want to return "2".
How is this achieve able with GoMock?
mock.on("FunctionName", "someStringArgument").Return(...)
Suppose if someStringArgument
is "hello" then I want to return "1". But if someStringArgument
is any other string I want to return "2".
How is this achieve able with GoMock?
What you want to do is write a custom function which will return your desired output.
Here is a simple example of what I do.
Define a custom response function
func FunctionNameResponse(arg String) string{
if arg == "hellp" {
// I used quotes because you mentioned "1" and not 1
return "1"
}
return "2"
}
Call custom function anywhere needed.
mock.on("FunctionName", mock.Anything).Return(FunctionNameResponse("someStringArgument"))