mock
mock copied to clipboard
Reference a call into a variable
Requested feature
A function to make a reference of a call into a call variable:
func Ref(dest **gomock.Call, call *gomock.Call) *gomock.Call {
*dest = call
return call
}
This func just assigns a call to a call variable.
Why this feature is needed
In easiest cases gomock.InOrder is more than enough to describe an order of calls. But once you spawn a goroutine it becomes a partial one. Consider an scheme where:
Parent thread makes calls calls Ax, spawn goroutines and then do some calls B1, …,Bm:
| A1 | A2 | … | An | spawn goroutines | B1 | … | Bm |
|---|
With such a reference helper you can do just several well-separated gomock.InOrder calls to ensure a proper order:
var anCall *gomock.Call
// order for the main thread
gomock.InOrder(A1, A2, …, gomock.Ref(&anCall, An), B1, …, Bm)
// orders for goroutines
gomock.InOrder(g11.After(anCall), g12, g13, …)
gomock.InOrder(g21.After(anCall), g22, g23, …)
…
BTW, it would be less needed, albeit not totally useless, if gomock.InOrder would return its last call as requested in https://github.com/golang/mock/issues/403