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

simplify mockgen usage for private interfaces #3769

Merged
merged 1 commit into from
Apr 19, 2023
Merged

Conversation

marten-seemann
Copy link
Member

I finally figured out a way to get rid of the horrible bash script currently used for mock generation: https://github.com/quic-go/quic-go/blob/af517bdef10a483bacd5eb96e67ebca4e4e151b2/mockgen_private.sh. libp2p/go-libp2p#2248 (comment) is what triggered this.

The trick is to export the type using a type alias, but to hide this behind a build flag:

//go:build gomock || generate

type MyInterface = myInterface

mockgen can then be called with the -build_flags="-tags=gomock" option to set the required build tag. And to be able to have the go generate command in the same file, the generate build flag is added to the file as well (go generate sets the generate build flag automatically).

@codecov
Copy link

codecov bot commented Apr 12, 2023

Codecov Report

Merging #3769 (2a85e4c) into master (379e7ec) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #3769   +/-   ##
=======================================
  Coverage   84.23%   84.23%           
=======================================
  Files         142      142           
  Lines       14084    14084           
=======================================
  Hits        11863    11863           
  Misses       1801     1801           
  Partials      420      420           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@marten-seemann marten-seemann merged commit c9a2f79 into master Apr 19, 2023
@marten-seemann marten-seemann deleted the mockgen-private branch April 19, 2023 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants