uber-go/mock

Do() should panic when given a function that returns values

ash2k opened this issue · 3 comments

ash2k commented

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!

r-hang commented

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.

ash2k commented

Yes. There may also be tests that pass but don't actually test what the author thinks they are testing.

tulzke commented

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)) {...}