-
Notifications
You must be signed in to change notification settings - Fork 101
WIP: Add gomock support #1102
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
base: main
Are you sure you want to change the base?
WIP: Add gomock support #1102
Conversation
aguidirh
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.
I really like this mock approach. Thanks @r4f4
- it generates the code automatically for you
- it is possible to reuse the mocked structs from a different package instead of duplicating code (as it is currently)
| @@ -247,75 +247,3 @@ func TestAdditionalImageCollector(t *testing.T) { | |||
| assert.ElementsMatch(t, expected, res) | |||
| }) | |||
| } | |||
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.
It is really nice to reuse the mock from other packages instead of duplicating them.
+1
| // Code generated by MockGen. DO NOT EDIT. | ||
| // Source: ./interface.go | ||
| // | ||
| // Generated by this command: | ||
| // | ||
| // mockgen -source=./interface.go -destination=./mock/interface_generated.go -package=mock | ||
| // | ||
|
|
||
| // Package mock is a generated GoMock package. |
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.
Generating the mock automatically based on the interface is really a big win.
+1
|
Issues go stale after 90d of inactivity. Mark the issue as fresh by commenting If this issue is safe to close now please do so with /lifecycle stale |
|
@r4f4 I really like this approach and I think oc-mirror could benefit a lot from it. Is there anything missing that we can do to have it merged ? |
Other than rebasing, I think it depends on what we want out of this PR. I just did it for one test file as an example but there still a lot of work to do it for the rest. |
|
Got it @r4f4, so maybe we can get this merged and use it as an example to migrate the older tests (it does not need to be all at once) and when creating new ones. What do you think about it @lmzuccarelli ? |
|
@r4f4 - could you rebase and once passing we can merge |
|
Stale issues rot after 30d of inactivity. Mark the issue as fresh by commenting If this issue is safe to close now please do so with /lifecycle rotten |
|
/remove-lifecycle rotten |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: r4f4 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This should make it easier to write dynamic mocks in unit tests.
|
@r4f4: The following tests failed, say
Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
|
PR needs rebase. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Description
Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.
Github / Jira issue:
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.
Expected Outcome
Please describe the outcome expected from the tests.