source mode: support specifying interfaces#281
Closed
abhinav wants to merge 1 commit intouber-go:mainfrom
Closed
Conversation
Adds an optional positional argument in -source mode to specify a comma-separated list of interfaces to generate mocks for. Resolves uber-go#140
c07938f to
907b46b
Compare
sywhang
reviewed
Oct 3, 2025
| var is []*model.Interface | ||
| for ni := range iterInterfaces(file) { | ||
| if _, ok := p.excludeNamesSet[ni.name.String()]; ok { | ||
| if p.wantIface != nil && !p.wantIface(ni.name.String()) { |
Contributor
There was a problem hiding this comment.
should we error out here if wantIface was never found in the file? I don't think we're currently erroring out when we specify a nonexistent interface name.
Contributor
Author
There was a problem hiding this comment.
Agreed that we should do that.
I didn't originally do that to retain existing behavior, but I have found it annoying/confusing when the mock doesn't get generated.
Archive mode also suffers from this, I think.
For now, I'm going to convert this PR to draft in favor of #200 since that was first, and the author has updated it.
Contributor
Author
|
Closing in favor of #200 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds an optional positional argument in -source mode
to specify a comma-separated list of interfaces to generate mocks for.
For backwards compatibility, if no interfaces are specified,
all interfaces in the source file will be mocked.
Performance:
Interface filtering is done during parsing instead of afterwards (versus #200).
Testing:
Includes unit tests for the new functionality,
as well as a usage test in internal/tests that uses this functionality.
Supersedes #200
Resolves #140