This release has two additions to the fake API for reading back what a fake was called with, a fix for a race in methods without return values, and a guide for anyone coming from gomock.
Inspecting calls
- ๐
<Method>Args()returns every call to a method as a slice of structs, with one exported field per argument:FakeMySpecialInterfaceDoThingsArgs{Arg1: "stuff", Arg2: 5}. You can check a whole call with oneEqualorcmp.Diff, and skip an argument withcmpopts.IgnoreFields. Function fakes get the same thing asArgs().ArgsForCallstill works as before. @dnephin asked for this in 2018. (#392, fixes #106) - ๐
CallOrder()returns the names of a fake's methods in the order they were called, so you can assert that, for example,Write()was called beforeCommit(). Order across two fakes still isn't recorded; the gomock guide has a stub recipe for that. (#394, fixes #113)
Fixes
- ๐ A method with no return values called its stub field again after unlocking, instead of the copy it took under the lock. Swapping the stub from another goroutine at that moment was a data race, and
Calls(nil)could panic the caller. Both templates call the copy now. (#389)
๐ Docs
- docs/migrating-from-gomock.md maps gomock's controller, expectations, matchers, call counts and ordering onto a fake's
Returns,Calls,ArgsForCall,CallCount,ArgsandCallOrder, with the same check shown in testing, testify and gomega.
๐งน Housekeeping
- โฌ๏ธ gomega 1.43.1 (#391). go-cmp is a direct dependency now because a spec imports it; it was already in go.mod through gomega, and a module that has counterfeiter as a tool sees no change.
- โฌ๏ธ CodeQL actions
- the one table test in the generator package is a spec suite like the rest (#393)
Regenerating produces a diff in every fake: the per-method record is the new struct type, and the fake keeps the call order.
Full Changelog: v6.13.0...v6.14.0