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 (27.77%) 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 57.62% 57.62%
=======================================
Files 26 26
Lines 1966 1966
=======================================
Hits 1133 1133
Misses 755 755
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
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
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 🚥 Pre-merge checks | ✅ 14 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (14 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
/retest |
b733de2 to
3cee832
Compare
23c2388 to
e6ccc93
Compare
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.
a21f9c5 to
bd47dfe
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
pkg/util/mocks/generate.go (1)
10-11:⚠️ Potential issue | 🟠 Major | ⚡ Quick winPin
mockgenversion ingo:generatedirectives to ensure reproducible mock generation.The
go:generatedirectives rungo run go.uber.org/mock/mockgenwithout a version pin, allowing the generator version to drift. This matches the concern previously raised in the past review.📌 Proposed fix
-//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 invoke go.run for go.uber.org/mock/mockgen without a version, allowing the generator to drift; update both directives in pkg/util/mocks/generate.go to pin a specific mockgen module version (e.g., change "go run go.uber.org/mock/mockgen" to "go run go.uber.org/mock/mockgen@vX.Y.Z") so mock generation is reproducible, and apply the same version pin to both the Client and StatusWriter directives.
🤖 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 7-8: The build uses mockgen version mismatch: the generate.go
comment (and docs) say to install go.uber.org/mock/mockgen@v0.6.0 but
go:generate will use the version pinned in go.mod (go.uber.org/mock v0.4.0).
Pick one approach and make them consistent: either update go.mod to require
go.uber.org/mock v0.6.0 so go:generate uses v0.6.0, or change the install
comment in pkg/util/mocks/generate.go (and docs/testing.md) to instruct
installing go.uber.org/mock/mockgen@v0.4.0 to match the existing go.mod; update
the //go:generate directives in generate.go only if you change the go.mod
version. Ensure the chosen version string (v0.6.0 or v0.4.0) is used everywhere.
---
Duplicate comments:
In `@pkg/util/mocks/generate.go`:
- Around line 10-11: The go:generate directives invoke go.run for
go.uber.org/mock/mockgen without a version, allowing the generator to drift;
update both directives in pkg/util/mocks/generate.go to pin a specific mockgen
module version (e.g., change "go run go.uber.org/mock/mockgen" to "go run
go.uber.org/mock/mockgen@vX.Y.Z") so mock generation is reproducible, and apply
the same version pin to both the Client and StatusWriter directives.
🪄 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: 80d73620-9333-4755-aba3-8dbd6b754fd0
⛔ 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 with no reviewable changes (1)
- go.mod
✅ Files skipped from review due to trivial changes (10)
- pkg/condition/conditions.go
- pkg/gcpclient/client.go
- pkg/util/mocks/doc.go
- pkg/util/mocks/projectclaim/customeresourceadapter.go
- pkg/util/mocks/gcpclient/client.go
- docs/testing.md
- config/config.go
- controllers/projectclaim/projectclaim_controller.go
- pkg/util/mocks/condition/conditions.go
- pkg/util/mocks/status-writer.go
de54a74 to
d0897cc
Compare
d0897cc to
457d7ec
Compare
457d7ec to
10c2877
Compare
Migrate from the archived github.com/golang/mock to the maintained fork go.uber.org/mock. Regenerate all mock files with the new mockgen.
10c2877 to
64b3f8b
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. |
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