Skip to content

🌱 Replace hand-written test mocks with gomock-generated mocks - #2775

Merged
openshift-merge-bot[bot] merged 1 commit into
operator-framework:mainfrom
pedjak:gomock-migration
Jun 22, 2026
Merged

🌱 Replace hand-written test mocks with gomock-generated mocks#2775
openshift-merge-bot[bot] merged 1 commit into
operator-framework:mainfrom
pedjak:gomock-migration

Conversation

@pedjak

@pedjakpedjak commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Description

Replace all hand-written mock structs across the test suite with go.uber.org/mock (gomock) generated mocks. This eliminates duplicated mocks, establishes a single consistent mocking pattern, and ensures mocks stay in sync with interface changes automatically via make generate-mocks.

Hand-written test code shrank by 373 lines (1901 added, 2274 removed). The generated mocks add 3580 lines, but those are auto-generated and never manually maintained.

Infrastructure

  • Add mockgen via bingo, consistent with how all other build tools are managed
  • Add generate-mocks Makefile target wired into generate/verify so CI catches stale mocks
  • //go:generate directives live in internal/testutil/mock/generate.go for all exported interfaces, and inline at interface definitions for unexported ones (trackingCache, sourcerer)
  • Generated mocks for unexported interfaces use _test.go files to keep go.uber.org/mock out of the production binary

Mock migration

  • ~40 hand-written mock structs removed across 20+ test files
  • 19 generated mock packages created under internal/testutil/mock/
  • 2 in-package generated mocks for unexported interfaces (source mode)
  • Mocks cover external interfaces (controller-runtime client, helm-operator-plugins, k8s apiextensions, logr, boxcutter machinery, k8s rbac validation, net/http) and internal interfaces (storage, applier, authorization, controllers, contentmanager, config, catalogd server/service, rukpak render)

Naming cleanup

  • Rename MockPuller/MockCacheFakePuller/FakeCache in image/fakes.go to clarify they are test fakes (preconfigured return values), not mocks (interaction verification)
  • Remove duplicated FakeCertProvider from render/fake.go and rukpak/util/testing/testing.go, replaced by generated MockCertificateProvider
  • FakeBundleSource (a function type, not an interface) retained as-is

Reviewer Checklist

  • API Go Documentation
  • Tests: Unit Tests (and E2E Tests, if appropriate)
  • Comprehensive Commit Messages
  • Links to related GitHub Issue(s)

CopilotAI review requested due to automatic review settings June 19, 2026 15:44
@netlify

netlifyBot commented Jun 19, 2026

Copy link
Copy Markdown

Deploy Preview for olmv1 ready!

NameLink
🔨 Latest commit39c3498
🔍 Latest deploy loghttps://app.netlify.com/projects/olmv1/deploys/6a37d59b3c9dcc0008241268
😎 Deploy Previewhttps://deploy-preview-2775--olmv1.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changesRun an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@pedjak
pedjak requested review from perdasilva and removed request for ankitathomasJune 19, 2026 15:46

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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 standardizes the repository’s test mocking approach by replacing hand-written mock implementations with go.uber.org/mock (gomock) generated mocks, and adds tooling + make targets to keep mocks regenerated and in sync with interface changes.

Changes:

  • Added mock generation infrastructure (bingo-managed mockgen, make generate-mocks, centralized go:generate directives).
  • Introduced generated gomock packages under internal/testutil/mock/** and migrated many tests to use them.
  • Kept/clarified true “test fakes” (preconfigured return values) vs interaction-verifying mocks (e.g., rename to FakePuller / FakeCache).

Reviewed changes

Copilot reviewed 56 out of 59 changed files in this pull request and generated 16 comments.

Show a summary per file
FileDescription
MakefileAdds mockgen symlink + generate-mocks target and wires it into make generate.
.bingo/Variables.mkInstalls mockgen via bingo and exposes MOCKGEN.
.bingo/variables.envAdds MOCKGEN env var for bingo tooling.
.bingo/mockgen.modAdds bingo module for mockgen.
.bingo/mockgen.sumAdds checksums for mockgen bingo module.
go.modAdds go.uber.org/mock dependency (and tidies indirect deps).
go.sumAdds go.uber.org/mock sums.
AGENTS.mdDocuments gomock as the standard for interface mocks + regeneration workflow.
internal/testutil/mock/generate.goCentralizes //go:generate mockgen ... directives for exported interfaces.
internal/testutil/mock/helmclient/interfaces.goAdds composite interface used for generating a combined helm client mock.
internal/testutil/mock/helmclient/mock_actionclient.goGenerated mocks for helm-operator-plugins action interfaces/getter.
internal/testutil/mock/helmclient/mock_composite.goGenerated mock for composite helm interface.
internal/testutil/mock/ctrlclient/mock_client.goGenerated mocks for controller-runtime client.Client and sub-writers.
internal/testutil/mock/crdclient/mock_crdinterface.goGenerated mock for CRD typed client interface.
internal/testutil/mock/logrsink/mock_logsink.goGenerated mock for logr.LogSink.
internal/testutil/mock/httputil/mock_roundtripper.goGenerated mock for net/http.RoundTripper.
internal/testutil/mock/rbac/mock_rulesresolver.goGenerated mock for Kubernetes RBAC rule resolver.
internal/testutil/mock/machinery/mock_results.goGenerated mocks for boxcutter machinery result interfaces.
internal/testutil/mock/storage/mock_instance.goGenerated mock for catalogd storage Instance.
internal/testutil/mock/catalogdserver/mock_catalogstore.goGenerated mock for catalogd server CatalogStore.
internal/testutil/mock/catalogdservice/mock_graphqlservice.goGenerated mock for catalogd GraphQLService.
internal/testutil/mock/catalogclient/mock_cache.goGenerated mock for catalogmetadata client cache interface.
internal/testutil/mock/config/mock_schemaprovider.goGenerated mock for config SchemaProvider.
internal/testutil/mock/contentmanager/mock_contentmanager.goGenerated mock for contentmanager Manager.
internal/testutil/mock/cmcache/mock_cache.goGenerated mocks for contentmanager cache interfaces.
internal/testutil/mock/controllers/mock_controllers.goGenerated mocks for operator-controller controller interfaces.
internal/testutil/mock/authorization/mock_authorization.goGenerated mock for authorization PreAuthorizer.
internal/testutil/mock/applier/mock_applier.goGenerated mocks for applier interfaces.
internal/testutil/mock/render/mock_certprovider.goGenerated mock for rukpak render CertificateProvider.
internal/shared/util/image/fakes.goRenames Mock* to Fake* for non-interaction fakes.
internal/shared/util/image/pull_test.goUpdates tests to use renamed fakes.
internal/shared/util/featuregates/logging_test.goMigrates to gomock-based LogSink mock.
internal/operator-controller/rukpak/render/fake.goRemoves duplicated handwritten cert provider fake (replaced by generated mock).
internal/operator-controller/rukpak/util/testing/testing.goRemoves duplicated handwritten cert provider fake from shared test util.
internal/operator-controller/rukpak/render/render_test.goSwitches to generated MockCertificateProvider.
internal/operator-controller/rukpak/render/certprovider_test.goSwitches to generated MockCertificateProvider.
internal/operator-controller/rukpak/render/registryv1/generators/generators_test.goSwitches to generated MockCertificateProvider with expectations.
internal/operator-controller/rukpak/preflights/crdupgradesafety/crdupgradesafety_test.goReplaces handwritten CRD getter with generated mock.
internal/operator-controller/controllers/clusterobjectset_controller.goAdds go:generate for unexported interface mock (source mode).
internal/operator-controller/controllers/mock_trackingcache_gen_test.goAdds generated in-package mock for trackingCache (test-only).
internal/operator-controller/controllers/resolve_ref_test.goRefactors tests to use gomock-based helpers/mocks.
internal/operator-controller/controllers/clusterobjectset_controller_internal_test.goReplaces handwritten tracking cache with gomock-generated mock.
internal/operator-controller/controllers/suite_test.goReplaces handwritten controller deps with gomock-generated mocks/helpers.
internal/operator-controller/controllers/clustercatalog_controller_test.goReplaces handwritten catalog cache/populator mocks with gomock mocks.
internal/operator-controller/contentmanager/cache/cache.goAdds go:generate for sourcerer/watch/source mocks (test-only).
internal/operator-controller/contentmanager/cache/mock_sourcerer_gen_test.goAdds generated in-package mock for unexported interfaces (test-only).
internal/operator-controller/contentmanager/cache/cache_test.goMigrates tests to gomock-generated mocks.
internal/operator-controller/config/config_test.goMigrates schema-provider tests to gomock-generated mock.
internal/operator-controller/catalogmetadata/client/client_test.goMigrates cache and HTTP transport fakes to gomock mocks.
internal/operator-controller/authorization/rbac_test.goMigrates RBAC resolver test double to gomock mock.
internal/operator-controller/applier/provider_test.goMigrates manifest provider / certificate provider fakes to generated mocks.
internal/operator-controller/action/helm_test.goMigrates from testify/mock to gomock-generated helm client mocks.
internal/catalogd/serverutil/serverutil_test.goMigrates storage instance test double to generated gomock mock.
internal/catalogd/server/handlers_test.goMoves to server_test package and uses generated mocks.
internal/catalogd/controllers/core/clustercatalog_controller_test.goMigrates storage instance test double to generated gomock mock.
internal/operator-controller/applier/helm_test.goMigrates applier Helm tests to generated mocks and helper builders.
internal/operator-controller/applier/boxcutter_test.goMigrates boxcutter tests to generated mocks and helper builders.
Files not reviewed (2)
  • internal/operator-controller/contentmanager/cache/mock_sourcerer_gen_test.go: Generated file
  • internal/operator-controller/controllers/mock_trackingcache_gen_test.go: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadinternal/operator-controller/action/helm_test.go
Comment threadinternal/operator-controller/action/helm_test.go
Comment threadinternal/shared/util/featuregates/logging_test.go
Comment threadinternal/operator-controller/applier/boxcutter_test.go
Comment threadinternal/operator-controller/applier/boxcutter_test.go
Comment threadinternal/operator-controller/applier/boxcutter_test.go
Comment threadinternal/operator-controller/applier/boxcutter_test.go
Comment threadinternal/operator-controller/applier/boxcutter_test.go
Comment threadinternal/operator-controller/applier/boxcutter_test.go
Comment threadinternal/operator-controller/applier/boxcutter_test.go
@codecov

codecovBot commented Jun 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.46%. Comparing base (a12398a) to head (39c3498).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@ Coverage Diff @@## main #2775 +/- ##
==========================================
+ Coverage 66.78% 70.46% +3.67% 
==========================================
Files 149 143 -6 Lines 11386 10617 -769 ==========================================
- Hits 7604 7481 -123 + Misses 3222 2577 -645 + Partials 560 559 -1 
FlagCoverage Δ
e2e35.14% <0.00%> (+0.06%)⬆️
experimental-e2e52.58% <0.00%> (+0.03%)⬆️
unit59.49% <100.00%> (+7.37%)⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

CopilotAI review requested due to automatic review settings June 20, 2026 10:50

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 57 out of 60 changed files in this pull request and generated 3 comments.

Files not reviewed (2)
  • internal/operator-controller/contentmanager/cache/mock_sourcerer_gen_test.go: Generated file
  • internal/operator-controller/controllers/mock_trackingcache_gen_test.go: Generated file

Comment threadinternal/shared/util/featuregates/logging_test.go
Comment threadinternal/operator-controller/action/helm_test.go
@pedjak
pedjakforce-pushed the gomock-migration branch 2 times, most recently from 32a4020 to 3f7ec8eCompareJune 20, 2026 12:09
CopilotAI review requested due to automatic review settings June 20, 2026 12:09

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 57 out of 60 changed files in this pull request and generated 1 comment.

Files not reviewed (2)
  • internal/operator-controller/contentmanager/cache/mock_sourcerer_gen_test.go: Generated file
  • internal/operator-controller/controllers/mock_trackingcache_gen_test.go: Generated file

CopilotAI review requested due to automatic review settings June 20, 2026 16:30

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 56 out of 59 changed files in this pull request and generated no new comments.

Files not reviewed (2)
  • internal/operator-controller/contentmanager/cache/mock_sourcerer_gen_test.go: Generated file
  • internal/operator-controller/controllers/mock_trackingcache_gen_test.go: Generated file

CopilotAI review requested due to automatic review settings June 20, 2026 22:05

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 57 out of 60 changed files in this pull request and generated 1 comment.

Files not reviewed (2)
  • internal/operator-controller/contentmanager/cache/mock_sourcerer_gen_test.go: Generated file
  • internal/operator-controller/controllers/mock_trackingcache_gen_test.go: Generated file

Comment thread.bingo/Variables.mk
Introduce go.uber.org/mock (gomock) with mockgen code generation to
replace all hand-written mock structs across the test suite. This
eliminates duplicated mocks, establishes a single consistent mocking
pattern, and ensures mocks stay in sync with interface changes
automatically via make generate-mocks.
Infrastructure:
- Add mockgen via bingo with unversioned symlink for go generate
- Add generate-mocks Makefile target (go generate ./...)
- Wire into existing generate/verify targets for CI enforcement
- Centralized //go:generate directives in internal/testutil/mock/
for exported interfaces (external and internal)
- Source-mode directives at interface definitions for unexported
interfaces (trackingCache, sourcerer), output to _test.go files
to keep gomock out of the production binary
- Mock helpers accept shared *gomock.Controller to avoid controller
proliferation in nested mock scenarios
Rename MockPuller/MockCache to FakePuller/FakeCache in
image/fakes.go to clarify they are test fakes (preconfigured return
values), not mocks (interaction verification). Remove duplicated
FakeCertProvider from render/fake.go and rukpak/util/testing.go,
replaced by generated MockCertificateProvider. FakeBundleSource
(a function type, not an interface) is retained as-is.
Co-Authored-By: Claude <noreply@anthropic.com>
@perdasilva

Copy link
Copy Markdown
Contributor

Nice one! Thank you!

@perdasilva

Copy link
Copy Markdown
Contributor

/approve

@openshift-ciopenshift-ciBot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 22, 2026
@dtfranz

Copy link
Copy Markdown
Contributor

/lgtm

@openshift-ciopenshift-ciBot added the lgtm Indicates that a PR is ready to be merged. label Jun 22, 2026

@rashmigottipatirashmigottipati left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: perdasilva, rashmigottipati

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot
openshift-merge-botBot merged commit e4879a3 into operator-framework:mainJun 22, 2026
26 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approvedIndicates a PR has been approved by an approver from all required OWNERS files.lgtmIndicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@pedjak@perdasilva@dtfranz@rashmigottipati