mockgen deprecated: use uber-go/mock instead#943
mockgen deprecated: use uber-go/mock instead#943sebrandon1 wants to merge 1 commit intoopenshift:masterfrom
Conversation
84a65e1 to
baeadee
Compare
|
/retest |
baeadee to
1a08251
Compare
a5aad22 to
01dd97c
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 |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #943 +/- ##
=======================================
Coverage 46.28% 46.28%
=======================================
Files 98 98
Lines 12259 12259
=======================================
Hits 5674 5674
Misses 5935 5935
Partials 650 650
🚀 New features to boost your workflow:
|
01dd97c to
d66c1ca
Compare
|
/retest-required |
|
/cc |
Migrate from the archived github.com/golang/mock to the actively maintained go.uber.org/mock. Updates all imports, regenerates mocks, and fixes the InOrder API change in utils_test.go.
d66c1ca to
8e4a70e
Compare
WalkthroughThis pull request migrates the mock generation framework from Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
pkg/gcp/mock/client_generated.go (1)
3-7: Pin the mock generator invocation to avoid regen drift.All
go:generatedirectives in this codebase use a baremockgenbinary, which can resolve to either archivedgolang/mockorgo.uber.org/mockdepending on local PATH. Pin generation togo.uber.org/mock/mockgen(ideally with an explicit version) across all generation directives:
pkg/ibmcloud/client.gopkg/gcp/client.gopkg/aws/client.gopkg/azure/clients.goNote: The codebase has already migrated to
go.uber.org/mock/gomockimports, so no legacy import cleanup is needed.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/gcp/mock/client_generated.go` around lines 3 - 7, The generate directive currently calls the unqualified "mockgen" which can resolve to different binaries; update the go:generate lines that invoke mockgen (the lines mirroring the header in client_generated.go) to call the module-qualified binary "go.uber.org/mock/mockgen" instead of the bare "mockgen" (so the generated mock uses the uber/mock implementation consistently); apply the same change to the client go:generate directives for the other cloud client files that generate mocks (the client generation directives for GCP/AWS/Azure/IBM client mocks) so generation is pinned to the go.uber.org/mock/mockgen implementation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@go.mod`:
- Line 51: Add a pinned mockgen generator and update the //go:generate
invocations to call that pinned version: create a tools.go (e.g., package tools)
with a blank import for the generator module (go.uber.org/mock v0.6.0) to record
the tool in go.mod, then change the generate comments in pkg/aws/client.go,
pkg/gcp/client.go, pkg/ibmcloud/client.go, and pkg/azure/clients.go to invoke
the pinned generator explicitly (for example: use "go run
go.uber.org/mock/mockgen@v0.6.0 ..." in the //go:generate lines) so mock
regeneration is reproducible and tied to the go.mod entry you added.
---
Nitpick comments:
In `@pkg/gcp/mock/client_generated.go`:
- Around line 3-7: The generate directive currently calls the unqualified
"mockgen" which can resolve to different binaries; update the go:generate lines
that invoke mockgen (the lines mirroring the header in client_generated.go) to
call the module-qualified binary "go.uber.org/mock/mockgen" instead of the bare
"mockgen" (so the generated mock uses the uber/mock implementation
consistently); apply the same change to the client go:generate directives for
the other cloud client files that generate mocks (the client generation
directives for GCP/AWS/Azure/IBM client mocks) so generation is pinned to the
go.uber.org/mock/mockgen implementation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 056cff1a-a3d6-404f-a8de-1ab99a0c4a69
⛔ Files ignored due to path filters (11)
go.sumis excluded by!**/*.sumvendor/github.com/golang/mock/CONTRIBUTORSis excluded by!vendor/**,!**/vendor/**vendor/go.uber.org/mock/AUTHORSis excluded by!vendor/**,!**/vendor/**vendor/go.uber.org/mock/LICENSEis excluded by!vendor/**,!**/vendor/**vendor/go.uber.org/mock/gomock/call.gois excluded by!vendor/**,!**/vendor/**vendor/go.uber.org/mock/gomock/callset.gois excluded by!vendor/**,!**/vendor/**vendor/go.uber.org/mock/gomock/controller.gois excluded by!vendor/**,!**/vendor/**vendor/go.uber.org/mock/gomock/doc.gois excluded by!vendor/**,!**/vendor/**vendor/go.uber.org/mock/gomock/matchers.gois excluded by!vendor/**,!**/vendor/**vendor/go.uber.org/mock/gomock/string.gois excluded by!vendor/**,!**/vendor/**vendor/modules.txtis excluded by!vendor/**,!**/vendor/**
📒 Files selected for processing (29)
go.modpkg/aws/actuator/actuator_test.gopkg/aws/mock/client_generated.gopkg/azure/actuator_test.gopkg/azure/mock/client_generated.gopkg/cmd/provisioning/aws/create-iam-roles_test.gopkg/cmd/provisioning/aws/create_identity_provider_test.gopkg/cmd/provisioning/azure/create_managed_identities_test.gopkg/cmd/provisioning/azure/create_oidc_issuer_test.gopkg/cmd/provisioning/gcp/create_service_accounts_test.gopkg/cmd/provisioning/gcp/create_workload_identity_pool_test.gopkg/cmd/provisioning/gcp/create_workload_identity_provider_test.gopkg/cmd/provisioning/ibmcloud/create_service_id_test.gopkg/cmd/provisioning/ibmcloud/delete_service_id_test.gopkg/cmd/provisioning/ibmcloud/refresh-keys_test.gopkg/gcp/mock/client_generated.gopkg/ibmcloud/mock/client_generated.gopkg/operator/cleanup/cleanup_controller_test.gopkg/operator/credentialsrequest/credentialsrequest_controller_azure_test.gopkg/operator/credentialsrequest/credentialsrequest_controller_gcp_test.gopkg/operator/credentialsrequest/credentialsrequest_controller_test.gopkg/operator/credentialsrequest/credentialsrequest_controller_vsphere_test.gopkg/operator/credentialsrequest/status_test.gopkg/operator/podidentity/podidentitywebhook_controller_test.gopkg/operator/secretannotator/aws/reconciler_test.gopkg/operator/secretannotator/azure/mock/adal_generated.gopkg/operator/secretannotator/gcp/reconciler_test.gopkg/operator/secretannotator/vsphere/reconciler_test.gopkg/operator/utils/gcp/utils_test.go
| github.com/spf13/pflag v1.0.10 | ||
| github.com/stretchr/testify v1.11.1 | ||
| github.com/tidwall/gjson v1.18.0 | ||
| go.uber.org/mock v0.6.0 |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '== stale golang/mock references ==\n'
rg -n -C1 --glob '!vendor/**' 'github\.com/golang/mock' . || true
printf '\n== mock generation / tool pinning ==\n'
rg -n -C2 --glob '!vendor/**' 'go\.uber\.org/mock/mockgen|//go:generate .*mockgen|go install .*mockgen|go run .*mockgen|_ "go\.uber\.org/mock/mockgen"|^\s*tool\s+go\.uber\.org/mock/mockgen\b' . || trueRepository: openshift/cloud-credential-operator
Length of output: 2431
Pin the mockgen generator tool to ensure reproducible mock regeneration.
Line 51 adds the runtime dependency go.uber.org/mock v0.6.0, but the //go:generate mockgen invocations in pkg/aws/client.go, pkg/gcp/client.go, pkg/ibmcloud/client.go, and pkg/azure/clients.go remain unpinned. Without a pinned generator, future regenerations risk inconsistency or drift. Define and use a pinned mockgen entry (e.g., via tools.go, go install, or a tool wrapper) to guarantee reproducibility across environments.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@go.mod` at line 51, Add a pinned mockgen generator and update the
//go:generate invocations to call that pinned version: create a tools.go (e.g.,
package tools) with a blank import for the generator module (go.uber.org/mock
v0.6.0) to record the tool in go.mod, then change the generate comments in
pkg/aws/client.go, pkg/gcp/client.go, pkg/ibmcloud/client.go, and
pkg/azure/clients.go to invoke the pinned generator explicitly (for example: use
"go run go.uber.org/mock/mockgen@v0.6.0 ..." in the //go:generate lines) so mock
regeneration is reproducible and tied to the go.mod entry you added.
|
@sebrandon1: The following tests 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