Use go generate
directives for mock generation
#3159
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Instead of adding commands to the Makefile, use go generate directives in the files which contain the interfaces we want to mock. This approach has the following advantages:
code and not have to edit the makefiles.
specify the filepath, interface name and the path to the generated
mock.
work without modification.
I have left some commands in the makefile for generating mocks from code in
pkg
, and from autogenerated code. We could in theory get rid of these usages as well, but I did not feel there was much point at this time since they are edge cases.You may note that there are a lot of additional lines of code: this is because I'm using the "source" mode of mockgen instead of the "reflect" mode. The source mode will generate mocks for all interfaces in the file, and not just the specified ones. However, it does so much quicker than the reflect mode -
make gen
now takes about half the time it did previously.Summary
Provide a brief overview of the changes and the issue being addressed.
Explain the rationale and any background necessary for understanding the changes.
List dependencies required by this change, if any.
Fixes #(related issue)
Change Type
Mark the type of change your PR introduces:
Testing
Outline how the changes were tested, including steps to reproduce and any relevant configurations.
Attach screenshots if helpful.
Review Checklist: