-
Notifications
You must be signed in to change notification settings - Fork 47
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
mock: Add mockgen workflow #313
Conversation
0f821e1
to
6740c26
Compare
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.
Very cool to see the gomock
package in action!
I really like fact that we can generate very dynamic mocks on demand. And the way to use them also looks pretty easy to get started with.
This example use case also shows nicely why it's great to work with mocks: one can more easily test all possible branches as you demonstrated by adding two additional test cases.
IMO we should have a discussion about using gomock
in lnd as well and take this PR as a base for the discussion.
6740c26
to
60df3ed
Compare
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.
Glad to see another mock in action!
Imo mock is a necessary component that's missing from our unit tests. It makes tests much easier and, in particular, since we have many goroutines flying around, I find it very helpful to validate whether a call does happen inside another goroutine.
As mentioned before, lnd
and naut
have already started using mocks (thanks to @bhandras!). The challenge I see for lnd
is that it's missing interfaces, where it makes the mocking impossible. There is an ongoing effort made by @Crypt-iQ where we want to build more interfaces inside lnd's peer
. And we def need more to make the mocking happen.
That being said, what's your opinion about the two tools, go/mock
and testify/mock
? Curious about your preference here. I chose testify/mock
because we were already using testify
inside lnd
and from this article. Tbh I don't have that much experience using mocks inside go so that choice is more or less like, we just need A mock😂
When we get native fuzzing in golang, mocks will be very helpful. Since I imagine the golang fuzzer is coverage-driven, it is good to separate components and make them "dumb" to not confuse the coverage signals (e.g. so they don't spawn goroutines, have nondeterministic behavior, etc). Also if you want to run a lot of fuzzers, you don't want something like an |
- `make mock`: generates all the mocks for testing. - `mock-check`: generates all the mocks + checks if any *.go file changed. - `make gen`: generates all the auto generated files (protos + mocks). - Add `mock-check` to our CI
60df3ed
to
5b3b93f
Compare
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.
LGTM, just a few nits 🎉
Sorry if I'm being extra nit-picky, but if this is going to be our template for mock-usage, things should look extra tidy because they are going to be copy/pasted a lot 😅
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.
Go mock go!
Create mocks for `sidecar/interfaces.go` and `internal/test/interfaces.go` and use them for rewriting the `TestRegisterSidecar`.
5b3b93f
to
08921b5
Compare
Just waiting for @Roasbeef's opinion on using generated mocks, otherwise this is ready to be merged. |
make mock
: generates all the mocks for testing.mock-check
: generates all the mocks + checks if any *.go file changed.make gen
: generates all the auto generated files (protos + mocks).mock-check
to our CICreate mocks for
sidecar/interfaces.go
andinternal/test/interfaces.go
and use them for rewriting theTestRegisterSidecar
.