-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow mocking methods updating referenced structs
Some methods in Go take a pointer to a struct or a map and are supposed to set some values in the referenced argument. Using Return is not enough to mock such methods. We are introducing a Run method that allows setting a Call handler to make your mock update such referenced values. Example usage mocking a service that finds a user in a data store and fills the values in the provided struct: ```go m.On("Find", 1, mock.AnythingOfType(*User)) .Return(nil) .Run(func(args mock.Arguments) { u := args.Get(0).(*User) u.ID = 1 u.Email = "[email protected]" }) ```
- Loading branch information
1 parent
e22aedd
commit a369d6f
Showing
2 changed files
with
57 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters