I have the file util.go
:
func Foo(service *SomeService) error {
return helper(service)
}
func helper(service *SomeService) error {
...
}
I'm writing unit tests using testify
, starting with Foo
. I want to:
- mock
helper
- assert mocked
helper
was called 1 time
I saw some promising solutions at https://stackoverflow.com/a/19168875/1661745, but not sure about them:
Method 1: pass helper as parameter of Foo
. My doubt: testify needs a Mock struct to AssertNumberOfCalls, and here there is no struct.
Method 2: create a struct for Foo
. My doubt: I don't know if it makes sense to make a struct for utils. Also requires more refactoring since callers of Foo
would need a utils struct.
What's the best way to do this?