Feat: added OnFunc to mock using method directly and MockCall to mock quick methods #1678
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.
Summary
This PR introduces enhancements to the mocking library, allowing for more robust and refactor-friendly mocking of methods.
Changes
Examples
Previously, mocking a method required writing the method name as a string, which could lead to issues during renaming or refactoring. Additionally, mocking methods with multiple return values involved writing extensive conditional logic. The new functionalities simplify these processes significantly.
First we need to setup a mock
By using OnFunc, you can directly reference the method, making the code more robust against refactoring.
Now, we need to mock the call method inside the module as well
Using MockCall, you can mock methods with multiple return values in a cleaner and more concise manner, reducing the amount of boilerplate code.
These enhancements make the mocking library easier to use and maintain, providing a more intuitive and error-resistant approach to mocking methods.
Motivation
After three weeks using golang I believe theese changes were necessary to improve the usability and maintainability of the mocking library. By allowing direct method references, we reduce the risk of errors during renaming or refactoring. The MockCall function simplifies the mocking process, making the code cleaner and easier to maintain.
Observations and comments with the aim of improving the proposal will be well received because my only intention is to contribute to the evolution of the project.
Related issues
N/A