Skip to content

feat: migrate locking mocks from pegomock to uber-go/mock (Phase 1)#6253

Merged
jamengual merged 10 commits intomainfrom
feat/pegomock-to-gomock-migration
Feb 24, 2026
Merged

feat: migrate locking mocks from pegomock to uber-go/mock (Phase 1)#6253
jamengual merged 10 commits intomainfrom
feat/pegomock-to-gomock-migration

Conversation

@jamengual
Copy link
Copy Markdown
Contributor

@jamengual jamengual commented Feb 23, 2026

Summary

  • Migrate server/core/db and server/core/locking mock generation from pegomock to uber-go/mock (mockgen)
  • Update all 15 consumer test files to coexist with both frameworks during the incremental migration
  • Add go.uber.org/mock v0.6.0 as a direct dependency
  • Add implementation plan (docs/IMPLEMENTATION_PLAN.md) tracking the 6-stage migration

This 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

Aspect Pegomock (before) Gomock (after)
Constructor NewMockLocker() NewMockLocker(gomock.NewController(t))
Stubbing When(mock.Method(Any[T]())).ThenReturn(v) mock.EXPECT().Method(gomock.Any()).Return(v)
Verify once mock.VerifyWasCalledOnce().Method() mock.EXPECT().Method().Times(1) (before action)
Unstubbed calls Returns zero values Panics — requires .AnyTimes() for incidental calls

Files changed (20)

  • 4 go:generate directives updated
  • 4 mock files regenerated with mockgen
  • 2 test files fully rewritten (pure gomock)
  • 13 test files updated for coexistence
  • 1 implementation plan added

Test plan

  • go test ./server/core/locking/ -count=1 — all 23 locking tests pass
  • go test ./server/events/ -count=1 — all events tests pass
  • go test ./server/controllers/ -count=1 — all controller tests pass
  • go test ./server/... -count=1 — full server test suite passes
  • go mod tidy — clean module state
  • CI pipeline passes

Copilot AI review requested due to automatic review settings February 23, 2026 05:27
@dosubot
Copy link
Copy Markdown

dosubot bot commented Feb 23, 2026

Related Documentation

Checked 0 published document(s) in 1 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

@dosubot dosubot bot added feature New functionality/enhancement go Pull requests that update Go code labels Feb 23, 2026
@github-actions github-actions bot added dependencies PRs that update a dependency file size/l labels Feb 23, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 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/db and server/core/locking go:generate directives to use mockgen, 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.0 to 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.

Comment thread server/core/locking/locking_test.go
…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>
@jamengual jamengual force-pushed the feat/pegomock-to-gomock-migration branch from 3977d65 to 408b4d2 Compare February 23, 2026 05:36
Signed-off-by: Jose Amengual <jamengual@gmail.com>
Signed-off-by: PePe Amengual <2208324+jamengual@users.noreply.github.com>
@jamengual jamengual force-pushed the feat/pegomock-to-gomock-migration branch from 2e64c38 to 424133f Compare February 23, 2026 05:43
Comment thread server/events/command_runner_test.go
…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>
@jamengual
Copy link
Copy Markdown
Contributor Author

Addressed the skipApplyLockCheckerSetup feedback — replaced the boolean flag with two TestConfig fields (applyLockCheckerReturn, applyLockCheckerErr) that let tests configure what the AnyTimes() catch-all returns.

Before: Conditional flag to skip setup + explicit EXPECT after setup
After: Always register AnyTimes() with TestConfig-provided return values — tests that care set the values, others get zero-value defaults

See commit b586582.

lukemassa
lukemassa previously approved these changes Feb 23, 2026
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 23, 2026
Comment thread docs/IMPLEMENTATION_PLAN.md Outdated
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.

Is this file needed? If so, could it be named more specifically for the uber-go/mock adoption?

@jamengual
Copy link
Copy Markdown
Contributor Author

jamengual commented Feb 24, 2026 via email

Signed-off-by: PePe Amengual <2208324+jamengual@users.noreply.github.com>
@jamengual jamengual merged commit 9124dc8 into main Feb 24, 2026
41 checks passed
@jamengual jamengual deleted the feat/pegomock-to-gomock-migration branch February 24, 2026 21:06
jon-walton added a commit to jon-walton/atlantis that referenced this pull request Mar 2, 2026
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>
jon-walton added a commit to jon-walton/atlantis that referenced this pull request Mar 2, 2026
- 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>
aidansteele pushed a commit to aidansteele/atlantis that referenced this pull request Mar 12, 2026
…unatlantis#6253)

Signed-off-by: PePe Amengual <2208324+jamengual@users.noreply.github.com>
Signed-off-by: Jose Amengual <jamengual@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies PRs that update a dependency file feature New functionality/enhancement go Pull requests that update Go code lgtm This PR has been approved by a maintainer size/l

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants