Background
Per @rawahars's review on #2647: the go:generate directive should reside in the test file, and we should validate generated mocks in CI.
Goals
- Add a
//go:generate directive (in a TEST file) for each controller that has mocks.
- Add CI validation that runs
go generate ./... and fails if there is any diff against the committed mock files. This catches mock drift when interfaces change but mocks are not regenerated.
Affected packages
internal/controller/device/scsi/
internal/controller/device/plan9/
internal/controller/device/vpci/
internal/controller/network/
internal/controller/vm/
internal/windows/ (mock at internal/windows/mock/)
internal/gcs/ (GuestDefinedCapabilities mock at internal/gcs/mock/)
cmd/containerd-shim-lcow-v2/service/
Future controllers should follow the same convention.
Suggested CI step
Extend an existing lint job in .github/workflows/ci.yml:
- name: Verify generated mocks are up to date
run: |
go generate ./...
git diff --exit-code -- '*/mocks/*.go' '*/mock/*.go'
Run on windows-latest so build tags resolve correctly.
Acceptance criteria
Notes
Discussed in #2647 (review on internal/controller/network/network_lcow.go).
Background
Per @rawahars's review on #2647: the
go:generatedirective should reside in the test file, and we should validate generated mocks in CI.Goals
//go:generatedirective (in a TEST file) for each controller that has mocks.go generate ./...and fails if there is any diff against the committed mock files. This catches mock drift when interfaces change but mocks are not regenerated.Affected packages
internal/controller/device/scsi/internal/controller/device/plan9/internal/controller/device/vpci/internal/controller/network/internal/controller/vm/internal/windows/(mock atinternal/windows/mock/)internal/gcs/(GuestDefinedCapabilitiesmock atinternal/gcs/mock/)cmd/containerd-shim-lcow-v2/service/Future controllers should follow the same convention.
Suggested CI step
Extend an existing lint job in
.github/workflows/ci.yml:Run on
windows-latestso build tags resolve correctly.Acceptance criteria
//go:generatedirective in a test filego generate ./...produces no diff against committed mocks on a fresh cloneNotes
Discussed in #2647 (review on
internal/controller/network/network_lcow.go).