Skip to content

test(dbauthz): migrate TestFile tests to mocked db #19268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

hugodutka
Copy link
Contributor

Starts migrating dbauthz tests to mocked db, following the approach in #19257.

What this does

  • Converts the TestFile group to use s.Mocked with dbmock
  • Seeds data with testutil.Fake (gofakeit)
  • Adds gomock expectations for:
    • GetFileByHashAndCreator
    • GetFileByID
    • GetFileIDByTemplateVersionID
    • InsertFile
  • Handles dbauthz fallback by expecting GetFileTemplates

Rationale
This reduces reliance on spinning up a real DB for these tests, making them faster and easier to iterate on. Tracks progress toward coder/internal#869.

Testing

  • go test ./coderd/database/dbauthz -run TestMethodTestSuite/TestFile

Notes

  • Kept the scope intentionally small (one test group) to keep the review focused.

Refs: coder/internal#869

…with dbmock and gofakeit\n- Add expectations for GetFileByHashAndCreator, GetFileByID, GetFileIDByTemplateVersionID, InsertFile\n- Seed data with testutil.Fake\n\nRefs: coder/internal#869\nCo-authored-by: hugodutka <28019628+hugodutka@users.noreply.github.com>
@hugodutka hugodutka closed this Aug 9, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Aug 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant