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

mock: AssertCalled confuses separate method calls in assert message #1144

Open
mortenlj opened this issue Jan 12, 2022 · 3 comments · May be fixed by #1258
Open

mock: AssertCalled confuses separate method calls in assert message #1144

mortenlj opened this issue Jan 12, 2022 · 3 comments · May be fixed by #1258
Labels
help wanted pkg-mock Any issues related to Mock

Comments

@mortenlj
Copy link

I have the following setup:

	mockHandler.
		On("Apply",
			mock.AnythingOfType("*v1.ReplicaSet"),
			mock.AnythingOfType("*v1.Secret"),
			mock.Anything).
		Return(nil).
	mockHandler.
		On("Cleanup", mock.AnythingOfType("*v1.Secret"), mock.Anything).
		Return(nil)

After exercising my code, I want to assert that Cleanup was called:

mockHandler.AssertCalled(t, "Cleanup", mock.AnythingOfType("*v1.Secret"), mock.Anything)

In the case where my code only has called Apply, and not called Cleanup, I get an error like this:

        	Test:       	TestManager_ApplyFailed
        	Messages:   	Expected "Cleanup" to have been called with:
        	            	[*v1.Secret mock.Anything]
        	            	but actual calls were:
        	            	        [nil &Secret{ObjectMeta:{      0 0001-01-01 00:00:00 +0000 UTC <nil> <nil> map[] map[one:1] [] []  []},Data:map[string][]byte{},Type:,StringData:map[string]string{},Immutable:nil,} <nil>]

This seems weird, because Cleanup does not take those arguments. The explanation is that the "actual calls" in this list are calls to Apply, which are not relevant when looking for calls of Cleanup. At the very least, the list of calls should mention the name of the method.

@kleinerhund
Copy link

Having the same issue. AssertCalled fails for the right reasons (for me it was a decimal type where 1^1 != 100^-2), but the inclusion of false calls got pretty annoying. Opened PR #1258

@dolmen dolmen added the pkg-mock Any issues related to Mock label Oct 16, 2023
@dolmen dolmen changed the title AssertCalled confuses separate method calls in assert message mock: AssertCalled confuses separate method calls in assert message Oct 16, 2023
@dolmen
Copy link
Collaborator

dolmen commented Oct 16, 2023

Please provide a test case that shows the issue and that runs on go.dev/play. That will help to check (now or later) if this issue is already fixed or not.

@mortenlj
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted pkg-mock Any issues related to Mock
Projects
None yet
3 participants