CNF-23386: mockgen deprecated: use uber-go/mock instead#271
Conversation
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (32.25%) is below the target coverage (50.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## master #271 +/- ##
=======================================
Coverage 58.34% 58.34%
=======================================
Files 26 26
Lines 1942 1942
=======================================
Hits 1133 1133
Misses 731 731
Partials 78 78
🚀 New features to boost your workflow:
|
c11bebf to
006c69e
Compare
006c69e to
3369ef4
Compare
|
/retest |
b036341 to
c29b305
Compare
|
@sebrandon1: This pull request references CNF-23386 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "5.0.0" version, but no target version was set. DetailsIn response to this:
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 openshift-eng/jira-lifecycle-plugin repository. |
c29b305 to
b733de2
Compare
WalkthroughSwitch mock tooling to go.uber.org/mock: update go.mod and docs, change //go:generate lines to run mockgen via ChangesMock Generation Tool Migration
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (1 error)
✅ Passed checks (14 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
/retest |
b733de2 to
3cee832
Compare
3cee832 to
23c2388
Compare
23c2388 to
e6ccc93
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: sebrandon1 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
@sebrandon1: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions 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. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pkg/util/mocks/generate.go`:
- Around line 10-11: The go:generate directives in pkg/util/mocks/generate.go
currently call go.uber.org/mock/mockgen without a version which allows the
generator to drift; update the two directives (the lines invoking mockgen for
Client and StatusWriter) to pin a specific mockgen module version (e.g., append
`@v0.6.0` to go.uber.org/mock/mockgen) and make the same pinning change wherever
else mockgen is invoked (e.g., pkg/condition/conditions.go) so generated mocks
remain reproducible and consistent with the repo's intended generator version.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Central YAML (inherited)
Review profile: CHILL
Plan: Enterprise
Run ID: 718b54c6-cb76-41b5-a370-8766127eafc1
⛔ Files ignored due to path filters (1)
go.sumis excluded by!**/*.sum
📒 Files selected for processing (13)
config/config.gocontrollers/projectclaim/projectclaim_controller.godocs/testing.mdgo.modpkg/condition/conditions.gopkg/gcpclient/client.gopkg/util/mocks/condition/conditions.gopkg/util/mocks/cr-client.gopkg/util/mocks/doc.gopkg/util/mocks/gcpclient/client.gopkg/util/mocks/generate.gopkg/util/mocks/projectclaim/customeresourceadapter.gopkg/util/mocks/status-writer.go
✅ Files skipped from review due to trivial changes (6)
- pkg/util/mocks/doc.go
- config/config.go
- docs/testing.md
- pkg/util/mocks/gcpclient/client.go
- controllers/projectclaim/projectclaim_controller.go
- pkg/util/mocks/status-writer.go
🚧 Files skipped from review as they are similar to previous changes (3)
- pkg/gcpclient/client.go
- pkg/util/mocks/projectclaim/customeresourceadapter.go
- pkg/util/mocks/condition/conditions.go
| //go:generate go run go.uber.org/mock/mockgen -destination ./cr-client.go -package mocks sigs.k8s.io/controller-runtime/pkg/client Client | ||
| //go:generate go run go.uber.org/mock/mockgen -destination ./status-writer.go -package mocks sigs.k8s.io/controller-runtime/pkg/client StatusWriter |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "Find unpinned mockgen go:generate directives:"
rg -nP 'go run go\.uber\.org/mock/mockgen(?!@)' pkg/util/mocks/generate.go pkg/condition/conditions.go
echo
echo "Compare documented/pinned versions:"
rg -n 'go\.uber\.org/mock|mockgen@' go.mod docs/testing.md pkg/util/mocks/generate.go pkg/condition/conditions.goRepository: openshift/gcp-project-operator
Length of output: 1366
Pin mockgen in go:generate directives to keep mock outputs reproducible.
pkg/util/mocks/generate.goandpkg/condition/conditions.goboth rungo run go.uber.org/mock/mockgenwithout an@version(there are existing references to@v0.6.0, whilego.modcurrently usesgo.uber.org/mock v0.4.0).- Pinning the generator version prevents silent drift in generated mock code.
Proposed change
-//go:generate go run go.uber.org/mock/mockgen -destination ./cr-client.go -package mocks sigs.k8s.io/controller-runtime/pkg/client Client
-//go:generate go run go.uber.org/mock/mockgen -destination ./status-writer.go -package mocks sigs.k8s.io/controller-runtime/pkg/client StatusWriter
+//go:generate go run go.uber.org/mock/mockgen@v0.6.0 -destination ./cr-client.go -package mocks sigs.k8s.io/controller-runtime/pkg/client Client
+//go:generate go run go.uber.org/mock/mockgen@v0.6.0 -destination ./status-writer.go -package mocks sigs.k8s.io/controller-runtime/pkg/client StatusWriter-//go:generate go run go.uber.org/mock/mockgen -destination=../util/mocks/$GOPACKAGE/conditions.go -package=$GOPACKAGE -source conditions.go
+//go:generate go run go.uber.org/mock/mockgen@v0.6.0 -destination=../util/mocks/$GOPACKAGE/conditions.go -package=$GOPACKAGE -source conditions.go📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| //go:generate go run go.uber.org/mock/mockgen -destination ./cr-client.go -package mocks sigs.k8s.io/controller-runtime/pkg/client Client | |
| //go:generate go run go.uber.org/mock/mockgen -destination ./status-writer.go -package mocks sigs.k8s.io/controller-runtime/pkg/client StatusWriter | |
| //go:generate go run go.uber.org/mock/mockgen@v0.6.0 -destination ./cr-client.go -package mocks sigs.k8s.io/controller-runtime/pkg/client Client | |
| //go:generate go run go.uber.org/mock/mockgen@v0.6.0 -destination ./status-writer.go -package mocks sigs.k8s.io/controller-runtime/pkg/client StatusWriter |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@pkg/util/mocks/generate.go` around lines 10 - 11, The go:generate directives
in pkg/util/mocks/generate.go currently call go.uber.org/mock/mockgen without a
version which allows the generator to drift; update the two directives (the
lines invoking mockgen for Client and StatusWriter) to pin a specific mockgen
module version (e.g., append `@v0.6.0` to go.uber.org/mock/mockgen) and make the
same pinning change wherever else mockgen is invoked (e.g.,
pkg/condition/conditions.go) so generated mocks remain reproducible and
consistent with the repo's intended generator version.
https://github.com/golang/mock is marked as archived as of
June 27, 2023. They recommend using go.uber.org/mock.This PR attempts to change the dependency to one that is maintained.
Tracking issue: redhat-best-practices-for-k8s/telco-bot#45
Summary by CodeRabbit
Chores
Documentation
Tests