Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Hard to debug when a Do(fn) function no longer matches its mock signature #71

Closed
EtiennePerot opened this issue May 19, 2017 · 2 comments · Fixed by #395 or #558
Closed

Hard to debug when a Do(fn) function no longer matches its mock signature #71

EtiennePerot opened this issue May 19, 2017 · 2 comments · Fixed by #395 or #558
Assignees

Comments

@EtiennePerot
Copy link

Situation: we had code like:

type Foo interface {
  Bar(arg1, arg2 string)
  ...
}

and tests like:

do := func(arg1, arg2 string) { ... }
// ... bunch of code ...
myBarMock.EXPECT().Bar(wantArg1, wantArg2).Do(do)

Then we added an argument to Bar:

type Foo interface {
  Bar(arg1, arg2, arg3 string)
  ...
}

and updated the EXPECT():

do := func(arg1, arg2 string) { ... }
// ... bunch of code ...
myBarMock.EXPECT().Bar(wantArg1, wantArg2, wantArg3).Do(do)

... but forgot to update do. The result was "panic: reflect: Call with too many input arguments" with no strong indication that what was wrong was the do function, rather than some place where the third argument hadn't been added (e.g. missing wantArg3).
It would be nice if the message said something more obvious like "EXPECT.()Do() function doesn't match the mock signature".

@codyoss
Copy link
Member

codyoss commented Jan 15, 2020

This seems reasonable. We are open to PRs 😸

@cvgw cvgw self-assigned this Jan 17, 2020
cvgw added a commit that referenced this issue Feb 2, 2020
Update the error handling for Call.Do in the case where
the argument passed to Call.Do does not match expectations.

* panic if the argument is not a function
* panic if the number of input arguments do not match those expected by Call
* panic if the types of the input arguments do not match those expected
by Call
* panic if the number of return arguments do not match those expected by
Call
* panic if the types of return arguments do not match those expected by
Call
cvgw added a commit that referenced this issue Feb 2, 2020
Update the error handling for Call.Do in the case where
the argument passed to Call.Do does not match expectations.

* panic if the argument is not a function
* panic if the number of input arguments do not match those expected by Call
* panic if the types of the input arguments do not match those expected
by Call
* panic if the number of return arguments do not match those expected by
Call
* panic if the types of return arguments do not match those expected by
Call
cvgw added a commit that referenced this issue Feb 2, 2020
Update the error handling for Call.Do in the case where
the argument passed to Call.Do does not match expectations.

* panic if the argument is not a function
* panic if the number of input arguments do not match those expected by Call
* panic if the types of the input arguments do not match those expected
by Call
* panic if the number of return arguments do not match those expected by
Call
* panic if the types of return arguments do not match those expected by
Call
cvgw added a commit that referenced this issue Feb 2, 2020
Update the error handling for Call.Do in the case where
the argument passed to Call.Do does not match expectations.

* panic if the argument is not a function
* panic if the number of input arguments do not match those expected by Call
* panic if the types of the input arguments do not match those expected
by Call
* panic if the number of return arguments do not match those expected by
Call
* panic if the types of return arguments do not match those expected by
Call
cvgw added a commit that referenced this issue Feb 2, 2020
Update the error handling for Call.Do in the case where
the argument passed to Call.Do does not match expectations.

* panic if the argument is not a function
* panic if the number of input arguments do not match those expected by Call
* panic if the types of the input arguments do not match those expected
by Call
* panic if the number of return arguments do not match those expected by
Call
* panic if the types of return arguments do not match those expected by
Call
cvgw added a commit that referenced this issue Feb 2, 2020
Update the error handling for Call.Do in the case where
the argument passed to Call.Do does not match expectations.

* panic if the argument is not a function
* panic if the number of input arguments do not match those expected by Call
* panic if the types of the input arguments do not match those expected
by Call
* panic if the number of return arguments do not match those expected by
Call
* panic if the types of return arguments do not match those expected by
Call
cvgw added a commit that referenced this issue Feb 2, 2020
Update the error handling for Call.Do in the case where
the argument passed to Call.Do does not match expectations.

* panic if the argument is not a function
* panic if the number of input arguments do not match those expected by Call
* panic if the types of the input arguments do not match those expected
by Call
* panic if the number of return arguments do not match those expected by
Call
* panic if the types of return arguments do not match those expected by
Call
cvgw added a commit that referenced this issue Feb 6, 2020
Update the error handling for Call.Do and Call.DoAndReturn in the case where
the argument passed does not match expectations.

* panic if the argument is not a function
* panic if the number of input arguments do not match those expected by Call
* panic if the types of the input arguments do not match those expected
by Call

Call.DoAndReturn has additional validations on the return signature

* panic if the number of return arguments do not match those expected by
Call
* panic if the types of return arguments do not match those expected by
Call
cvgw added a commit that referenced this issue Feb 6, 2020
Update the error handling for Call.Do and Call.DoAndReturn in the case where
the argument passed does not match expectations.

* panic if the argument is not a function
* panic if the number of input arguments do not match those expected by Call
* panic if the types of the input arguments do not match those expected
by Call

Call.DoAndReturn has additional validations on the return signature

* panic if the number of return arguments do not match those expected by
Call
* panic if the types of return arguments do not match those expected by
Call
cvgw added a commit that referenced this issue Feb 28, 2020
Update the error handling for Call.Do and Call.DoAndReturn in the case where
the argument passed does not match expectations.

* panic if the argument is not a function
* panic if the number of input arguments do not match those expected by Call
* panic if the types of the input arguments do not match those expected
by Call

Call.DoAndReturn has additional validations on the return signature

* panic if the number of return arguments do not match those expected by
Call
* panic if the types of return arguments do not match those expected by
Call
cvgw added a commit that referenced this issue Feb 28, 2020
Update the error handling for Call.Do and Call.DoAndReturn in the case where
the argument passed does not match expectations.

* panic if the argument is not a function
* panic if the number of input arguments do not match those expected by Call
* panic if the types of the input arguments do not match those expected
by Call

Call.DoAndReturn has additional validations on the return signature

* panic if the number of return arguments do not match those expected by
Call
* panic if the types of return arguments do not match those expected by
Call
cvgw added a commit that referenced this issue Feb 28, 2020
Update the error handling for Call.Do and Call.DoAndReturn in the case where
the argument passed does not match expectations.

* panic if the argument is not a function
* panic if the number of input arguments do not match those expected by Call
* panic if the types of the input arguments do not match those expected
by Call

Call.DoAndReturn has additional validations on the return signature

* panic if the number of return arguments do not match those expected by
Call
* panic if the types of return arguments do not match those expected by
Call
@cvgw cvgw closed this as completed in #395 Feb 28, 2020
cvgw added a commit that referenced this issue Feb 28, 2020
Update the error handling for Call.Do and Call.DoAndReturn in the case where
the argument passed does not match expectations.

* panic if the argument is not a function
* panic if the number of input arguments do not match those expected by Call
* panic if the types of the input arguments do not match those expected
by Call

Call.DoAndReturn has additional validations on the return signature

* panic if the number of return arguments do not match those expected by
Call
* panic if the types of return arguments do not match those expected by
Call
@cvgw
Copy link
Collaborator

cvgw commented May 8, 2020

Reopening since the fix was reverted

@cvgw cvgw reopened this May 8, 2020
@codyoss codyoss added this to the v1.6.0 milestone May 14, 2021
codyoss added a commit that referenced this issue May 14, 2021
Previous behavior was a panic would happen if the number of args
did not match. Now the test should fail more gracefully and allow
for better debugging.

Fixes: #71
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.