fix(mocks): migrate test mocks to go.uber.org/mock - #3463
fix(mocks): migrate test mocks to go.uber.org/mock#3463Dave Shoup (shouples) wants to merge 2 commits into
go.uber.org/mock#3463Conversation
The go-generate pre-commit hook could not pass: mocker (unmaintained since 2020) fails against the repo's current golang.org/x/tools, so `go generate` errored and contributors bypassed the hook with --no-verify. Finish the migration the repo already started (Flink was on mockgen) rather than pin a dead tool. - Convert the 10 mocker //go:generate directives to `go run go.uber.org/mock/ mockgen` reflect mode; regenerate the auth/io/form/local mocks. - Rewrite the mocker struct-of-func-field call sites to gomock EXPECT() across 7 test files; migrate the mock/client.go helper. - Normalize the 13 Flink directives to `go run` (no PATH-installed mockgen) and regenerate; pin go.uber.org/mock v0.4.0 -> v0.5.2 so generation is reproducible and the hook passes. - Delete the dead PassThroughFileSystem helper and the orphaned launch_darkly directive. travisjeffery/mocker remains an indirect dependency (transitively required by cmf-sdk-go and ccloud-sdk-go-v1-public); no first-party usage remains. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR completes the repository’s migration from the unmaintained travisjeffery/mocker generator to go.uber.org/mock (mockgen) for Go mock generation, restoring reliability of go generate ./... and the associated pre-commit hook without affecting the shipped CLI binary.
Changes:
- Replaced multiple
//go:generatedirectives to usego run go.uber.org/mock/mockgen(including typed mocks where applicable) and regenerated mocks. - Updated unit tests to use Uber GoMock controller/EXPECT style instead of the prior function-field mock structs.
- Bumped
go.uber.org/mockdependency tov0.5.2and updatedgo.sum.
Reviewed changes
Copilot reviewed 28 out of 44 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/mock/prompt.go | Regenerated Prompt mock using Uber mockgen (typed) in pkg/mock. |
| pkg/mock/filesystem.go | Regenerated FileSystem mock using Uber mockgen (typed) in pkg/mock. |
| pkg/mock/filesystem_pt.go | Removed now-unused pass-through helper tied to the old mocker-style mocks. |
| pkg/local/confluent_home.go | Updated go:generate to use go run go.uber.org/mock/mockgen for ConfluentHome. |
| pkg/local/confluent_current.go | Updated go:generate to use go run go.uber.org/mock/mockgen for ConfluentCurrent. |
| pkg/io/io.go | Updated go:generate to use go run go.uber.org/mock/mockgen for FileSystem. |
| pkg/form/prompt.go | Updated go:generate to use go run go.uber.org/mock/mockgen for Prompt. |
| pkg/form/form_test.go | Migrated test to use gomock.Controller + EXPECT() on new mock type. |
| pkg/form/field_test.go | Migrated tests to use gomock.Controller + EXPECT() on new mock type. |
| pkg/flink/test/mock/table_view_mock.go | Regenerated mock output (includes new isgomock field and clearer arg names). |
| pkg/flink/test/mock/store_mock.go | Updated generated header/path output for mockgen invocation. |
| pkg/flink/test/mock/statement_controller_mock.go | Regenerated mock output (new arg names + isgomock). |
| pkg/flink/test/mock/reverse_i_search_mock.go | Regenerated mock output (new arg names + isgomock). |
| pkg/flink/test/mock/result_fetcher_mock.go | Regenerated mock output (new arg names + isgomock). |
| pkg/flink/test/mock/prompt_mock.go | Regenerated mock output (new arg names + isgomock). |
| pkg/flink/test/mock/output_controller_mock.go | Regenerated mock output (adds isgomock). |
| pkg/flink/test/mock/mock_generator.go | Switched mock generation directives to go run go.uber.org/mock/mockgen and added one new generator entry. |
| pkg/flink/test/mock/json_rpc2_conn.go | Regenerated mock output (renamed args, varargs naming, adds isgomock). |
| pkg/flink/test/mock/input_controller_mock.go | Regenerated mock output (renamed args, adds isgomock). |
| pkg/flink/test/mock/gateway_client_mock.go | Regenerated mock output (renamed args, adds isgomock). |
| pkg/flink/test/mock/console_parser_mock.go | Regenerated mock output (adds isgomock). |
| pkg/flink/test/mock/cmf_client_mock.go | Updated generated header/path output and modernized interface{} to any in signature. |
| pkg/flink/test/mock/application_controller_mock.go | Regenerated mock output (adds isgomock). |
| pkg/featureflags/feature_flags.go | Removed obsolete go:generate directive referencing mocker. |
| pkg/cmd/prerunner_test.go | Rewrote mocks from function-field style to gomock-generated mocks and expectations. |
| pkg/auth/mds_client.go | Updated go:generate to use go run go.uber.org/mock/mockgen for MDSClientManager. |
| pkg/auth/login_organization_manager.go | Updated go:generate to use go run go.uber.org/mock/mockgen for LoginOrganizationManager. |
| pkg/auth/login_credentials_manager.go | Updated go:generate to use go run go.uber.org/mock/mockgen for LoginCredentialsManager. |
| pkg/auth/login_credentials_manager_test.go | Updated tests to use new gomock-generated Prompt mock. |
| pkg/auth/ccloud_client_factory.go | Updated go:generate to use go run go.uber.org/mock/mockgen for CCloudClientFactory. |
| pkg/auth/auth_token_handler.go | Updated go:generate to use go run go.uber.org/mock/mockgen for AuthTokenHandler. |
| mock/login_organization_manager.go | Regenerated root-level mock using Uber mockgen (typed). |
| mock/confluent_home.go | Regenerated root-level mock using Uber mockgen (typed). |
| mock/client.go | Updated helper factory to return a gomock-generated mock and set expectations via EXPECT(). |
| mock/ccloud_client_factory.go | Regenerated root-level mock using Uber mockgen (typed). |
| mock/auth_token_handler.go | Regenerated root-level mock using Uber mockgen (typed). |
| mock/auth_mds_client.go | Regenerated root-level mock using Uber mockgen (typed). |
| internal/logout/command_test.go | Updated logout tests to use gomock-generated mocks + controller plumbing. |
| internal/login/command_test.go | Updated login tests to use gomock-generated mocks + helper constructors for expectations. |
| internal/local/command_services_test.go | Updated tests to use gomock-generated ConfluentHome/ConfluentCurrent mocks. |
| go.sum | Updated checksums for go.uber.org/mock to v0.5.2. |
| go.mod | Bumped go.uber.org/mock dependency to v0.5.2. |
Files not reviewed (15)
- mock/auth_mds_client.go: Generated file
- mock/auth_token_handler.go: Generated file
- mock/ccloud_client_factory.go: Generated file
- mock/confluent_current.go: Generated file
- mock/confluent_home.go: Generated file
- mock/login_credentials_manager.go: Generated file
- mock/login_organization_manager.go: Generated file
- pkg/flink/test/mock/application_controller_mock.go: Generated file
- pkg/flink/test/mock/cmf_client_mock.go: Generated file
- pkg/flink/test/mock/console_parser_mock.go: Generated file
- pkg/flink/test/mock/gateway_client_mock.go: Generated file
- pkg/flink/test/mock/input_controller_mock.go: Generated file
- pkg/flink/test/mock/json_rpc2_conn.go: Generated file
- pkg/flink/test/mock/output_controller_mock.go: Generated file
- pkg/flink/test/mock/prompt_mock.go: Generated file
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
🎉 All Contributor License Agreements have been signed. Ready to merge. |
|
go.uber.org/mock





Release Notes
No user-facing changes. This is a contributor-tooling / test-infrastructure change; the shipped CLI binary is byte-for-byte unaffected (the mocks and
go.uber.org/mockare test-only).Checklist
Whatsection below whether this PR applies to Confluent Cloud, Confluent Platform, or both.Test & Reviewsection below.Blast Radiussection below.Cloud/Platform verification and feature-flag items are N/A: this changes only test mocks and their generators, not the shipped CLI. "Added tests" means the existing tests that used the old mocks were rewritten to the new library with their assertions preserved - no new commands to test.
What
The
go-generatepre-commit hook (go generate ./...) had stopped passing on a current Go toolchain:Contributors have been nudged toward one of two workarounds, both of which just paper over the broken hook:
SKIP=go-generate git commit ...- surgical (it disables only the broken hook), but it relies on every contributor knowing the incantation and remembering it on every commit, and it silently masks that code generation is broken rather than fixing it.git commit --no-verify- blunter still: it skips every pre-commit hook (go-fmt,go-mod-tidy, merge-conflict/YAML/whitespace checks), so formatting and hygiene checks quietly stop running too.This PR fixes the hook by finishing a migration the repo had already started, rather than disabling it.
Root cause:
travisjeffery/mocker, the generator behind most//go:generatedirectives, has been unmaintained since 2020 and no longer resolves packages under a currentgolang.org/x/tools. The repo was already mid-migration togo.uber.org/mock(mockgen, already used by Flink). This PR finishes that migration: everymockerdirective is rewritten tomockgen, all mocks are regenerated, and the affected test call sites are rewritten to the new library's style with their assertions preserved. First-partymockeris dropped fromgo.mod(it remains only as a transitive dependency of two Confluent SDKs). The hook stays enabled and now passes.Important
Most of this diff's line count is
mockgenregeneration output that needs no line-by-line review. Of the 44 files, 22 were edited by hand (each linked to its diff below); the rest are regenerated mocks.The files to actually review:
//go:generatedirectives (a line or two each,mocker->go run go.uber.org/mock/mockgen):pkg/auth/auth_token_handler.gopkg/auth/ccloud_client_factory.gopkg/auth/login_credentials_manager.gopkg/auth/login_organization_manager.gopkg/auth/mds_client.gopkg/io/io.gopkg/form/prompt.gopkg/local/confluent_current.gopkg/local/confluent_home.gopkg/flink/test/mock/mock_generator.go(13 Flink directives switched off a baremockgenbinary ontogo run)pkg/featureflags/feature_flags.go- deletes an orphaned directive whose target was already goneEXPECT(), assertions preserved as.Times(n)):internal/login/command_test.gointernal/logout/command_test.gointernal/local/command_services_test.gopkg/auth/login_credentials_manager_test.gopkg/cmd/prerunner_test.gopkg/form/field_test.gopkg/form/form_test.gomock/client.go- the one hand-written file undermock/(a helper, not generated); itsNewCCloudClientFactoryMockis rewritten to gomockgo.mod/go.sum- drops first-partytravisjeffery/mocker, bumpsgo.uber.org/mockversionpkg/mock/filesystem_pt.go- deleted (dead code, gomock-incompatible, no consumers)Everything else - the remaining
mock/*.go,pkg/mock/*.go, andpkg/flink/test/mock/*_mock.gois regenerated output.Applies to: neither Cloud nor Platform. Contributor tooling only; no change to the shipped binary.
Blast Radius
No customer impact - this touches only test mocks, their
//go:generatedirectives, and a test-only dependency, none of which ship in the CLI binary. Contributor-facing effect:go generate ./...is reproducible again (a second run yields a cleangit diff), so the pre-commit hook passes on a normal commit and there is no longer a reason to reach for--no-verifyand skip every other hook.References
Test & Review
go run go.uber.org/mock/mockgen -versionresolves with no PATH-installed tool.go generate ./...succeeds and a second run leaves a cleangit diff(proves the directives match the committed output).go build ./...andgo vet ./...are clean.go test ./pkg/form/... ./pkg/auth/... ./internal/login/... ./internal/logout/... ./pkg/cmd/....grep -R "travisjeffery/mocker" go.modreturns nothing for a first-party (non-// indirect) entry.go-generatehook end to end.