Do() should panic when given a function that returns values
ash2k opened this issue · 3 comments
I've just spent an hour debugging a test where I by mistake used Do(func () string { ... return "some value" })
instead of DoAndReturn()
. Do()
just discarded the value and mock returned an empty string.
Do()
should error out ASAP when given a function that returns values.
Thank you for the library!
If I understand your issue correctly, this proposal turns a current no-op operation into a panic, which may break lots of existing tests that rely on this no-op behavior. One way to address this seems to be some type of linting to prevent this.
Yes. There may also be tests that pass but don't actually test what the author thinks they are testing.
Maybe it's worth excluding the return values from the function passed to Do? It's about the case when we pass the -typed
flag to mockgen.
Example:
type SomeInterface{
Action(value int) (bool, error)
}
func (MockSomeInterface) Do(func(value int)) {...}
func (MockSomeInterface) DoAndReturn(func(value int) (bool, error)) {...}