Skip to content

fix(mocks): migrate test mocks to go.uber.org/mock - #3463

Open
Dave Shoup (shouples) wants to merge 2 commits into
mainfrom
djs/migrate-mocker-to-mockgen
Open

fix(mocks): migrate test mocks to go.uber.org/mock#3463
Dave Shoup (shouples) wants to merge 2 commits into
mainfrom
djs/migrate-mocker-to-mockgen

Conversation

@shouples

@shouples Dave Shoup (shouples) commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

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/mock are test-only).

Checklist

  • I have successfully built and used a custom CLI binary, without linter issues from this PR.
  • I have clearly specified in the What section below whether this PR applies to Confluent Cloud, Confluent Platform, or both.
  • I have verified this PR in Confluent Cloud pre-prod or production environment, if applicable.
  • I have verified this PR in Confluent Platform on-premises environment, if applicable.
  • I have attached manual CLI verification results or screenshots in the Test & Review section below.
  • I have added appropriate CLI integration or unit tests for any new or updated commands and functionality.
  • I confirm that this PR introduces no breaking changes or backward compatibility issues.
  • I have indicated the potential customer impact if something goes wrong in the Blast Radius section below.
  • I have put checkmarks below confirming that the feature associated with this PR is enabled in:
    • Confluent Cloud prod
    • Confluent Cloud stag
    • Confluent Platform
    • Check this box if the feature is enabled for certain organizations only

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-generate pre-commit hook (go generate ./...) had stopped passing on a current Go toolchain:

> go run github.com/travisjeffery/mocker/cmd/mocker --version
1.1.1
> pre-commit run go-generate --all-files
go generate..............................................................Failed
- hook id: go-generate
- exit code: 1

...
<datetime> mocker: failed to mock: loading packages failed
exit status 1
<file1>: running "go": exit status 1
<datetime> mocker: failed to mock: loading packages failed
exit status 1
<file2>: running "go": exit status 1
<datetime> mocker: failed to mock: loading packages failed
exit status 1
etc
...

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:generate directives, has been unmaintained since 2020 and no longer resolves packages under a current golang.org/x/tools. The repo was already mid-migration to go.uber.org/mock (mockgen, already used by Flink). This PR finishes that migration: every mocker directive is rewritten to mockgen, all mocks are regenerated, and the affected test call sites are rewritten to the new library's style with their assertions preserved. First-party mocker is dropped from go.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 mockgen regeneration 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:

Everything else - the remaining mock/*.go, pkg/mock/*.go, and pkg/flink/test/mock/*_mock.go is 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:generate directives, 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 clean git diff), so the pre-commit hook passes on a normal commit and there is no longer a reason to reach for --no-verify and skip every other hook.

References

  • Base of a small stack of contributor-tooling / logging fixes.
  • Internal: "Migration Guide from Mocker to Uber Gomock" (Confluence ADP page 3233284437).

Test & Review

  • go run go.uber.org/mock/mockgen -version resolves with no PATH-installed tool.
  • go generate ./... succeeds and a second run leaves a clean git diff (proves the directives match the committed output).
  • go build ./... and go vet ./... are clean.
  • The migrated packages pass: go test ./pkg/form/... ./pkg/auth/... ./internal/login/... ./internal/logout/... ./pkg/cmd/....
  • grep -R "travisjeffery/mocker" go.mod returns nothing for a first-party (non-// indirect) entry.
  • The migration commit itself was made through the normal (non-bypassed) pre-commit path, exercising the re-enabled go-generate hook end to end.

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>
Copilot AI lite review requested due to automatic review settings August 21, 2026 15:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:generate directives to use go 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/mock dependency to v0.5.2 and updated go.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.

@confluent-cla-assistant

Copy link
Copy Markdown

🎉 All Contributor License Agreements have been signed. Ready to merge.
Please push an empty commit if you would like to re-run the checks to verify CLA status for all contributors.

@sonarqube-confluent

Copy link
Copy Markdown

@shouples
Dave Shoup (shouples) marked this pull request as ready for review August 21, 2026 22:03
@shouples
Dave Shoup (shouples) requested a review from a team as a code owner August 21, 2026 22:03
@shouples Dave Shoup (shouples) changed the title fix(mocks): migrate test mocks to go.uber.org/mock fix(mocks): migrate test mocks to go.uber.org/mock Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants