Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consider optional expected calls last. #907

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rubensayshi
Copy link
Contributor

For a lot of our testsuite we're using mocks as a replacement of some services which in most tests we just want to return something simple and not care too much about them,
except for the tests where we're actually testing if the service is being used properly.

So we had the idea to put some On().Maybe() calls with Anything params on the mocks using the helper which we're already using to build up the various services needed.

However that conflicts with the tests which actually want to mock and assert some method calls themselves because the optional calls are first in the .ExpectedCalls and the more specific calls are never actually reached.

eg;

	var ms1 = new(TestExampleImplementation)
	ms1.On("TheExampleMethod", Anything, Anything, Anything).Maybe().Return(0, nil)
	ms1.On("TheExampleMethod", 1, 2, 3).Return(4, nil)

I think this kinda breaks backwards compatibility, anyone who uses .Maybe() with Anything params and .Times() and has subsequent expected calls could have the methods called in a different other with this change ...

@dolmen dolmen added the pkg-mock Any issues related to Mock label Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants