-
Notifications
You must be signed in to change notification settings - Fork 155
add interfaces flag with unit test #200
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
Conversation
59bd1d7 to
2553835
Compare
|
Hey @JacobOaks , can you please take a look? |
|
Hey @kliukovkin! Thanks for the PR! I am in favor of having this feature, just two questions/comments:
|
- Instead of using an -interfaces flag, what do you think about having source mode read positional arguments (i.e., mockgen -source <path/to/file.go> InterfaceOne,InterfaceTwo) to align it with how reflect mode works? (If there are no positional arguments specified, we would parse all interfaces to keep backwards compatibility) - Instead of parsing and then dropping interfaces that aren't specified, can we simply not parse ones that aren't requested? This is similar to how the exclusion flag already works and would avoid some wasted computation.
Hey @JacobOaks ! Done, can you please review and let me know if that looks good? |
|
@JacobOaks hey Jacob! Gentle ping here. |
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.
Sorry for the delay. Looks good to me with some minor comments. Let's merge this when they are addressed.
mockgen/parse_test.go
Outdated
| wantErr: true, | ||
| }, | ||
| { | ||
| name: "missing interface (Baz not found)", |
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.
Could we also add a test case for accidentally specified duplicate requested interfaces?
mockgen/parse_test.go
Outdated
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got, err := filterInterfaces(tt.args.all, tt.args.requested) | ||
| if (err != nil) != tt.wantErr { |
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.
instead of wantErr being a bool, could we make this a string and compare the error contents?
mockgen/parse.go
Outdated
|
|
||
| // If there are interfaces provided as positional arguments, filter them | ||
| if len(ifaces) > 0 { | ||
| if pkg.Interfaces, err = filterInterfaces(pkg.Interfaces, ifaces); err != nil { | ||
| log.Fatalf("Filtering interfaces failed: %v", err) | ||
| } | ||
| } else { | ||
| // No interfaces provided, process all interfaces for backward compatibility | ||
| log.Printf("No interfaces specified, processing all interfaces") | ||
| } |
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.
FYI, this is still doing the thing @JacobOaks's comment advised against:
Instead of parsing and then dropping interfaces that aren't specified, can we simply not parse ones that aren't requested? This is similar to how the exclusion flag already works and would avoid some wasted computation.
…terInterfaces, update tests
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.
@sywhang This PR implements the changes you suggested in #281 (failing on missing expected interfaces).
@kliukovkin, thanks for updating. left some minor suggestions for improvements.
I see that the tests are failing, though.
Co-authored-by: Abhinav Gupta <[email protected]>
|
Updated according to feedback.
Thanks for the review @abhinav ! 🚀 |
|
@kliukovkin thanks for updating the PR - could you please check the CI test run results and update the checked in golden files for tests? |
@sywhang ran |
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.
Thank you!
This is a proposal for
-interfacesflag using source mode. Using this flag it is possible to list only required interfaces to be mocked in source mode. Currently, source mode mocks all interfaces which -source file contains.Thanks @KastenMike for raising this!
Fixes golang/mock#660