uber-go / mock

GoMock is a mocking framework for the Go programming language.
Apache License 2.0
1.85k stars 106 forks source link

Allow type-safe calls to be used in InOrder #78

Closed EstebanOlmedo closed 10 months ago

EstebanOlmedo commented 10 months ago

This modifies InOrder to receive variadic any instead of *Call, allowing users to use this function with type-safe generated Calls.

This implementation uses a type assertion to check if the provided arguments are *Calls or reflection to get the *Call when the arguments wrap one (generated code). If neither of the two cases are fullfiled then InOrder panics.

Fix #70.

marten-seemann commented 10 months ago

If neither of the two cases are fullfiled then that argument is ignored.

Would it make sense to panic? Today it's not possible to pass an invalid call to InOrder. It would be nice if I'd be notified right away if I mess up InOrder, otherwise this will be very hard to debug.

marten-seemann commented 10 months ago

Alternatively, what about a type-safe(r) way of doing this: Having InOrder accept an interface { Call() *Call }?

marten-seemann commented 10 months ago

Tested in quic-go in https://github.com/quic-go/quic-go/pull/4057. Seems to work. I also tested that it panic if I pass things other than gomock calls to InOrder.

🚢 it!

nkostoulas commented 5 months ago

This breaks InOrder() function calls that pass a []*gomock.Call slice 😞. It is therefore making it very hard for us to upgrade to a later version of this lib. Would it be sensible to fix or provide an alternative function with the previous method definition (and maybe using the new method internally instead)?

I can see it was previously proposed using an interface that implements a particular method instead. That would also be sensible. Perhaps this route could be revisited.