Skip to content
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

type-safe calls can't be used in gomock.InOrder #70

Closed
marten-seemann opened this issue Aug 28, 2023 · 0 comments · Fixed by #78
Closed

type-safe calls can't be used in gomock.InOrder #70

marten-seemann opened this issue Aug 28, 2023 · 0 comments · Fixed by #78
Assignees
Labels
bug Something isn't working

Comments

@marten-seemann
Copy link
Contributor

Actual behavior When using type-safe mode (-typed), the calls returned from EXPECT().Method() are typed. This is great, and a feature I've been waiting for for a long time. However, it makes it impossible to use them in gomock.InOrder, since InOrder expects a *gomock.Call.

Expected behavior I expected gomock.InOrder to work seamlessly.

To Reproduce Steps to reproduce the behavior

  1. Generate mocks using -typed
  2. Use gomock.InOrder with calls of that mock

Additional Information

  • gomock mode (reflect or source): reflect
  • gomock version or git ref: v0.2.0
  • golang version: Go 1.21

Triage Notes for the Maintainers

Failed CI run on quic-go after generating typed mocks: https://github.com/quic-go/quic-go/actions/runs/5988902088/job/16244553880?pr=4051 (PR: quic-go/quic-go#4051)

@r-hang r-hang added the bug Something isn't working label Aug 29, 2023
EstebanOlmedo added a commit that referenced this issue Sep 5, 2023
Currently when type-safe return values are used, one can't use
`InOrder` neither `After` with them as they expect
`*gomock.Call` as parameters. This introduces a new interface called
`WrapperCall` to support usage for this methods when typed
flag is used.

This interface helps to have compile-time error/warnings instead of
runtime errors with a reflection based solution.

Fixes (#70)
EstebanOlmedo added a commit that referenced this issue Sep 6, 2023
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 `*Call`s or reflection to get the `*Call` when the
arguments wrap one (generated code). If neither of the two cases are
fullfiled then that argument is ignored.

Fix #70.
EstebanOlmedo added a commit that referenced this issue Sep 7, 2023
Currently when type-safe return values are used, one can't use
`InOrder` neither `After` with them as they expect
`*gomock.Call` as parameters. This changes the type these functions
expect to be an interface which implements the `GetCall() *Call` method,
which returns the embedded `*gomock.Call` type for generated mock types.

Using this approach helps to have compile-time error/warnings instead of
runtime errors with a reflection based solution.

Fixes (#70)
sywhang added a commit that referenced this issue Sep 13, 2023
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 `*Call`s 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.

---------

Co-authored-by: Sung Yoon Whang <sungyoon@uber.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants