You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor: replace hand-written test mocks with gomock-generated mocks (#2775)
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>
extension-developer-e2e: $(OPERATOR_SDK)#EXHELP Run extension create, upgrade and delete tests.
290
302
go test -count=1 -v ./test/extension-developer-e2e/...
291
303
292
-
UNIT_TEST_DIRS := $(shell go list ./... | grep -vE "/test/|/testutils")$(shell go list ./test/internal/...)
304
+
UNIT_TEST_DIRS := $(shell go list ./... | grep -vE "/test/|/testutils|/testutil/mock")$(shell go list ./test/internal/...)
305
+
COVERAGE_PKGS := $(shell go list ./... | grep -vE "/test/|/testutils|/testutil/mock" | paste -sd,)
293
306
COVERAGE_UNIT_DIR := $(ROOT_DIR)/coverage/unit
294
307
295
308
.PHONY: envtest-k8s-bins #HELP Uses setup-envtest to download and install the binaries required to run ENVTEST-test based locally at the project/bin directory.
@@ -303,7 +316,7 @@ test-unit: $(SETUP_ENVTEST) envtest-k8s-bins #HELP Run the unit tests
303
316
KUBEBUILDER_ASSETS="$(shell $(SETUP_ENVTEST) use -p path $(ENVTEST_VERSION)$(SETUP_ENVTEST_BIN_DIR_OVERRIDE))"\
0 commit comments