-
Notifications
You must be signed in to change notification settings - Fork 105
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
build: use go generate for mocks #998
Conversation
Codecov Report
@@ Coverage Diff @@
## master #998 +/- ##
==========================================
- Coverage 72.33% 72.26% -0.08%
==========================================
Files 209 212 +3
Lines 23448 23508 +60
==========================================
+ Hits 16961 16987 +26
- Misses 5138 5169 +31
- Partials 1349 1352 +3
Flags with carried forward coverage won't be shown. Click here to find out more. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tACK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So how is this used? Do we need some docs?
You just need to run We didn't have any prior documentation to update for |
Opened #1003 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's move the directives next to the related types and add go generate ./...
to Makefile.
generate.go
Outdated
//go:generate mockgen -source=x/ecocredit/expected_keepers.go -package mocks -destination x/ecocredit/mocks/expected_keepers.go | ||
//go:generate mockgen -source=x/ecocredit/expected_keepers.go -package mocks -destination x/ecocredit/mocks/expected_keepers.go | ||
//go:generate mockgen -source=x/ecocredit/server/basket/keeper.go -package mocks -destination x/ecocredit/server/basket/mocks/keeper.go | ||
//go:generate mockgen -source=x/ecocredit/expected_keepers.go -package mocks -destination x/ecocredit/mocks/expected_keepers.go |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
normally we put the directive next to the related types. So the line above should be placed in x/ecocredit/expected_keepers.go file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can do. I found this as an example but looks like best practice is on a per file basis.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see why this was an example. You have to run go generate ./...
from within each directory and this was being used as a convenient way to generate all mocks with one command.
@aaronc , the advantage over make is:
|
Where should |
So
Or you have to navigate to each directory and run |
Would be happy to make changes but not sure how to best proceed? @robert-zaremba |
the issue was probably |
The issue is with multiple modules.
Simple
|
Makefile
Outdated
generate: | ||
find . -name 'go.mod' -type f -execdir sh -c 'go generate ./...' \; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will only work for go generate commands within the same directory as go.mod
. We had mockgen set up for server/core
and server/basket
but those were empty and unused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need to wrap the go generate command in sh
Makefile
Outdated
generate: | ||
find . -name 'go.mod' -type f -execdir sh -c 'go generate ./...' \; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need to wrap the go generate command in sh
Description
Closes: #817
Use
go generate
for generating mock code and add data module. Also removes unused mocks.Author Checklist
All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.
I have...
!
to the type prefix if API or client breaking changeCHANGELOG.md
Reviewers Checklist
All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.
I have...
!
in the type prefix if API or client breaking change