mockery
mockery copied to clipboard
Support mocking of methods that return functions with variadic arguments
Description
Previously mocking a method such as
LogMethodf(level string) func(msg string, a ...interface{})
gave a struct with method signature
LogMethodf(level string) func(msg string, a []interface{})
this resolves it so that the generated struct fulfils the original contract.
- Fixes #431
Type of change
- [X] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update
Version of Golang used when building/testing:
- [ ] 1.11
- [ ] 1.12
- [ ] 1.13
- [ ] 1.14
- [ ] 1.15
- [X] 1.16
- [ ] 1.17
- [ ] 1.18
How Has This Been Tested?
Extended existing variadic fixture to cover this case and checked that generated mock was as expected.
Checklist
- [X] My code follows the style guidelines of this project
- [X] I have performed a self-review of my code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [X] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my feature works
- [X] New and existing unit tests pass locally with my changes
I'm still getting to grips with the generator code. This feels a bit of a hack (we strip the slice markers and replace them with ellipses if we have figured it is variadic, is there a way to stop that being done in the first place? would appear to require modifying renderType
which is used in a lot of places). Also not fully clear on what generator tests to add.
There was also seeming a mock generated that didn't exist before - but since the interface exists in the example_project dir in the fixtures it seems this mock should exist?
Thanks for the update @alec-w . I am a bit swamped this week so I will take a look hopefully early next week.
would the only outstanding action here "Changes Requested"?
I believe so yes, I’d have to take another look to see if there was anything else I missed.
Closing this as there hasn't been any activity for a while. Please ping me with a new PR, or on this one, if it ever gets updated. Thanks!