-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Added support for getting the arguments of mock function call for a specific call count #1558
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, I do not think this API should be added because it does not encourage best testing practices. If testing for state then a mock can be prepared with the expected calls and AssertExpectations used.
Can you demonstrate a specific test case which can't be written using the existing API?
It's also quite unclear what a call "count" is in this context.
@@ -282,7 +282,7 @@ type Mock struct { | |||
ExpectedCalls []*Call | |||
|
|||
// Holds the calls that were made to this mocked object. | |||
Calls []Call | |||
Calls map[string][]Call |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a breaking change.
fmt.Println("ArgsForCallCount") | ||
fmt.Println(m.Calls) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not print.
Summary
The purpose of this change is to enable asserting the arguments of a mock function for a specific call count.
Changes
Updated the Mock struct to hold the map of methodName to a slice of calls instead of just a slice of Calls, this will be used to extract the calls for a given methodName easily
Motivation
For instance, when a method is invoked multiple times within the code, and there's a need to verify the arguments for a particular call count, this enhancement proves beneficial.
with the new API, can assert the argument for a second call like this .
Related issues
N/a