-
Notifications
You must be signed in to change notification settings - Fork 449
Add support for overriding configuration through comments on interfaces #1105
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
LandonTClipp
left a comment
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 is much, much better! I need to sit with this and ponder the implications of this PR a bit more. I might submit more comments in the coming days. Overall, this is probably close to being done.
| var yamlConfig []string | ||
|
|
||
| // Extract all mockery directive comments and build a YAML document | ||
| for _, doc := range decl.Doc.List { | ||
| // Look for directive comments `//mockery:<config-key>: <value>` and convert them to YAML | ||
| if value, found := strings.CutPrefix(doc.Text, "//mockery:"); found && value != "" { | ||
| yamlConfig = append(yamlConfig, value) | ||
| } | ||
| } |
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 can see that this is an easy and convenient way to translate into mockery config, but it might be nice to have some alternative syntax, rather than spreading yaml through multiple directive lines, especially if you could take advantage of the provided ast.ParseDirective function?
Something like this might be nicer, but I appreciate it may be a bit more work...
//mockery:generate -structname MyMock -filename my_mock.goThere 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 err on the side of being obvious versus being clever. Emulating command line args with mockery actually having any command line args is confusing and weird. I'm okay with the way this is currently implemented.
|
@paivagustavo I have a strange request, can you give me write permission on your fork? I have some tweaks I want to add to your branch regarding the |
Of course @LandonTClipp, I've added you! feel free to do any change :) |
|
@LandonTClipp your changes looks good to me! I've added one last commit to remove a println that I've added during some tests :). Thank you for having patience with me! |
Add docs and examples Bump minor version
9371cd6 to
f3eb94f
Compare
|
No worries, I think we're ready to merge this now once the tests pass. I bumped the minor version so it will get released automatically. Thanks again, this is great! |
|
Nice change, thanks @paivagustavo @LandonTClipp! 🎉 |
Description
Adds support for configuring mocks through directive comments on the interface. The comment will be parsed as a yaml configuration, any configuration supported on the file based config is also supported by this:
These configuration will take precedene of over any other configuration.
I haven't made any changes to documentation yet as I wanted to wait for a confirmation that this pr will be accepted before doing so.
Type of change
Version of Go used when building/testing:
How Has This Been Tested?
Added a new package with these annotations in the fixture folder, testing all the new configurations.
Checklist