-
Notifications
You must be signed in to change notification settings - Fork 416
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
Generate typed On_X functions to make updating mocks in tests faster #375
Conversation
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 really like the idea and it's something that's been heavily requested, but I have rejected the idea on the grounds that it introduces feature creep. This issue is a characteristic of testify and I hesitate to start introducing features that bifurcate mockery into two distinctly different behaviors. It would be more appropriate to introduce type safety into v3 where the default and only behavior is to be type safe. Otherwise I feel it's asking for trouble and creates a large maintenance burden down the line. So yes I really like the idea and wish mockery was type safe, but I don't feel comfortable introducing it in the current major version. |
Thanks for looking at this PR @LandonTClipp. The reason I did this is because refactoring code and updating the corresponding tests with the dynamic
I understand the desire to not add more features to maintain. I intentionally made this behavior optional and disabled by default so only users who opt-in by specify
I think bifurcating the behavior is inevitable in Go 1. If users want to continue to use mock-specific features such as |
Thank you for your thoughts, I will give it some more consideration. If you are willing to stay active and maintain the feature that will help. I do see the clear value it would provide, so let me think it over for a bit. |
can we generate wrappers around type SomeInterface interface {
SomeMethod func(int) err
} # generated
func (m *MockSomeInterface) On_SomeMethod(int) *Mock.call {
return m.On("SomeMethod", int)
} |
@aljorhythm The example you provided is nearly identical to what this PR adds. |
#396 looks like it solves this problem in a more flexible way. |
I am going to close this in favor of #396 because I like that schema a lot more. |
This PR adds a new
--generate-on-functions
option which, if enabled, will generate typedOn_
methods to make refactoring tests easier after an interface is changed.Because
mock.On
accepts any parameters mismatching types aren't detected until runtime which can make refactoring tests after an interface has changed non-trivial. If you use the generatedOn_
functions with this change refactoring tests can be much faster because the arguments and return values are checked by the compiler.