chore: Lazy mock initialization in artifact controller tests#101
Conversation
Replace eager initialization of all 11 mocks in SetupTest() with per-mock setup helpers. Each test now initializes only the mocks it actually uses, reducing total mock.Mock instances from ~352 to ~89 (75% reduction) and proportionally lowering race-detector overhead. Closes #100 Signed-off-by: Vadim Bauer <vb@container-registry.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughReworked the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Snapshot WarningsEnsure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice. Scanned FilesNone |
There was a problem hiding this comment.
Pull request overview
This PR updates the controller/artifact test suite to reduce testify/mock + race detector overhead by switching from eager initialization of all mocks in SetupTest() to per-test lazy initialization via dedicated setupXxx() helpers.
Changes:
- Refactored
SetupTest()to create only a barecontroller{}and reset mock fields tonil. - Added
setupXxx()helper methods to initialize and wire individual mocks into the controller on demand. - Updated each test (and mid-test resets) to initialize only the mocks it actually uses.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Preview images for this PR are available in
Verify a preview image: Verify SBOM attestation: |
The lazy mock initialization PR (#101) made SetupTest() reset all mocks to nil; tests must call setupXxx() helpers afterward. The fourth subtest in TestEnsureArtifact called SetupTest but never re-initialised c.repoMgr/c.artMgr/c.accMgr/c.abstractor, causing a nil pointer panic on the first .On() call. The panic was previously masked by the TestCopy infinite-recursion OOM (fixed by setting UTTEST=true in test-unit env). Signed-off-by: Vadim Bauer <vb@container-registry.com>
Summary
SetupTest()with per-mocksetupXxx()helpersmock.Mockinstances from ~352 to ~89 (75% reduction)sync.Mutexinstrumentation overhead under the race detectorRelated Issues
Closes #100 (Option 1: lazy mock initialization)
Type of Change
test:)Design
SetupTest()previously created all 11 mock objects and wired them into the controller for every test method (19 tests + 13 mid-test resets = 32 calls × 11 mocks = 352 instances). Many tests only use 1–3 mocks.The new approach:
SetupTest()nils all mock fields and creates a barecontroller{}setupXxx()helpers each create a fresh mock and wire it into the controllerc.SetupTest()+ specific setup calls) replace the previous blanket reinitializationMock creation count per test (before → after):
Testing
go test -count=1)go test -race)Checklist
git commit -s)Summary by CodeRabbit
Note: This release contains no user-facing changes. Updates are internal testing improvements.