feat: migrate locking mocks from pegomock to uber-go/mock (Phase 1)#6253
feat: migrate locking mocks from pegomock to uber-go/mock (Phase 1)#6253
Conversation
There was a problem hiding this comment.
Pull request overview
This PR begins an incremental migration of Atlantis’ locking- and db-related mocks/tests from pegomock to go.uber.org/mock (gomock), enabling both frameworks to coexist in the same test files during the transition.
Changes:
- Updated
server/core/dbandserver/core/lockinggo:generatedirectives to usemockgen, and regenerated the corresponding mock files. - Converted/updated affected unit tests to use gomock for the migrated mocks while retaining pegomock for remaining mocks.
- Added
go.uber.org/mock v0.6.0to module dependencies and introduced an implementation plan doc.
Reviewed changes
Copilot reviewed 19 out of 20 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| server/server_test.go | Uses gomock for locking mocks while keeping pegomock for template writer mocks. |
| server/server_internal_test.go | Converts db close tests from pegomock to gomock. |
| server/events/pull_closed_executor_test.go | Migrates locking locker usage to gomock within events tests. |
| server/events/project_locker_test.go | Rewrites project locker tests to gomock. |
| server/events/delete_lock_command_test.go | Uses gomock for locking locker while keeping pegomock for other mocks. |
| server/events/command_runner_test.go | Introduces gomock controllers for locking mocks and adds default “incidental call” expectations. |
| server/events/apply_command_runner_test.go | Updates apply-lock checks to gomock expectations. |
| server/core/locking/mocks/mock_locker.go | Regenerated Locker mock using MockGen. |
| server/core/locking/mocks/mock_apply_locker.go | Regenerated ApplyLocker mock using MockGen. |
| server/core/locking/mocks/mock_apply_lock_checker.go | Regenerated ApplyLockChecker mock using MockGen. |
| server/core/locking/locking_test.go | Migrated locking client tests from pegomock to gomock. |
| server/core/locking/locking.go | Switched Locker mock generation to mockgen. |
| server/core/locking/apply_locking.go | Switched ApplyLocker/ApplyLockChecker mock generation to mockgen. |
| server/core/db/mocks/mock_database.go | Regenerated Database mock using MockGen. |
| server/core/db/db.go | Switched Database mock generation to mockgen. |
| server/controllers/locks_controller_test.go | Uses gomock for locking mocks while keeping pegomock for remaining mocks. |
| server/controllers/api_controller_test.go | Uses gomock for Locker while keeping pegomock for remaining mocks. |
| go.mod | Adds go.uber.org/mock v0.6.0. |
| go.sum | Adds checksums for go.uber.org/mock v0.6.0. |
| docs/IMPLEMENTATION_PLAN.md | Adds a staged migration plan for the overall pegomock → gomock transition. |
…ock to uber-go/mock Phase 1 of incremental pegomock-to-gomock migration. Migrates the foundational mock interfaces (Database, Locker, ApplyLocker, ApplyLockChecker) and updates all 15 consumer test files to coexist with both frameworks during the transition. Key changes: - Update go:generate directives from pegomock to mockgen - Regenerate 4 mock files with uber-go/mock (mockgen) - Add go.uber.org/mock v0.6.0 as direct dependency - Convert locking_test.go and project_locker_test.go to pure gomock - Update 13 consumer test files for coexistence (gomock for locking mocks, pegomock for remaining events/vcs mocks) - Handle gomock's strict unexpected-call behavior with AnyTimes() catch-alls for incidental method calls - Add implementation plan tracking migration progress Replaces the abandoned big-bang approach from PR #5758 with an incremental strategy that keeps all tests green at each stage. Signed-off-by: PePe Amengual <2208324+jamengual@users.noreply.github.com>
Fix two instances of `Equals(t, err, err)` that compared an error to itself (always passing). Changed to `Equals(t, errExpected, err)` to properly validate the error path. Found by Copilot code review. Signed-off-by: Jose Amengual <jamengual@gmail.com> Signed-off-by: PePe Amengual <2208324+jamengual@users.noreply.github.com>
3977d65 to
408b4d2
Compare
Signed-off-by: Jose Amengual <jamengual@gmail.com> Signed-off-by: PePe Amengual <2208324+jamengual@users.noreply.github.com>
2e64c38 to
424133f
Compare
…rn value fields Instead of conditionally skipping the AnyTimes() expectation and requiring tests to register their own, use TestConfig fields (applyLockCheckerReturn, applyLockCheckerErr) to configure the return values directly. This removes the skipApplyLockCheckerSetup boolean and simplifies the setup pattern. Signed-off-by: PePe Amengual <2208324+jamengual@users.noreply.github.com>
|
Addressed the Before: Conditional flag to skip setup + explicit EXPECT after setup See commit b586582. |
There was a problem hiding this comment.
Is this file needed? If so, could it be named more specifically for the uber-go/mock adoption?
|
I will remove it.
…On Mon, Feb 23, 2026, 8:35 p.m. RB ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
On docs/IMPLEMENTATION_PLAN.md
<#6253 (comment)>
:
Is this file needed? If so, could it be named more specifically for the
uber-go/mock adoption?
—
Reply to this email directly, view it on GitHub
<#6253 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAQ3ERA67SYE7D3DJEG3VZ34NPIIFAVCNFSM6AAAAACV4JERGGVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZTQNBUHE4TSNZTGM>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Signed-off-by: PePe Amengual <2208324+jamengual@users.noreply.github.com>
Update test files to use gomock patterns following upstream's mock migration in runatlantis#6253. The db/mocks package now uses gomock, so tests that use MockDatabase need to: - Create a gomock.Controller - Pass controller to NewMockDatabase(ctrl) - Use EXPECT().Method().Return() instead of VerifyWasCalled() Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Jon Walton <jon.walton@cloverhealth.com>
- Migrate pr_controller_test.go to pure gomock patterns - Migrate output_persisting_project_command_runner_test.go to pure gomock - Regenerate ProjectCommandRunner mock with mockgen - Regenerate TemplateWriter mock with mockgen - Update related test files to use gomock for ProjectCommandRunner - Add X-Content-Type-Options header to mitigate XSS in jobs_controller This aligns with upstream's Phase 1 gomock migration (PR runatlantis#6253) to resolve merge conflicts and ensure PR runatlantis#6176 can be merged. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Jon Walton <jon.walton@cloverhealth.com>
…unatlantis#6253) Signed-off-by: PePe Amengual <2208324+jamengual@users.noreply.github.com> Signed-off-by: Jose Amengual <jamengual@gmail.com>
Summary
server/core/dbandserver/core/lockingmock generation from pegomock to uber-go/mock (mockgen)go.uber.org/mock v0.6.0as a direct dependencydocs/IMPLEMENTATION_PLAN.md) tracking the 6-stage migrationThis is Phase 1 of an incremental migration, replacing the abandoned big-bang approach from PR #5758. The coexistence pattern established here allows both pegomock and gomock to be used in the same test file — gomock for the migrated locking mocks, pegomock for remaining events/vcs mocks.
Key pattern changes
NewMockLocker()NewMockLocker(gomock.NewController(t))When(mock.Method(Any[T]())).ThenReturn(v)mock.EXPECT().Method(gomock.Any()).Return(v)mock.VerifyWasCalledOnce().Method()mock.EXPECT().Method().Times(1)(before action).AnyTimes()for incidental callsFiles changed (20)
go:generatedirectives updatedTest plan
go test ./server/core/locking/ -count=1— all 23 locking tests passgo test ./server/events/ -count=1— all events tests passgo test ./server/controllers/ -count=1— all controller tests passgo test ./server/... -count=1— full server test suite passesgo mod tidy— clean module state