Skip to content

refactor(test_db): use sqlx::test instead #411

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

Merged
merged 23 commits into from
May 31, 2025
Merged

Conversation

juleswritescode
Copy link
Collaborator

@juleswritescode juleswritescode commented May 28, 2025

While working on the completions for roles, I had unexpected test failures.

The reason was that roles are setup at the postgres-instance level, and while databases are unique to each test, all tests share the same instance.

To solve this problem, we'll use test migrations – there, we can set up a couple of roles, and use them throughout the test. Sqlx provides the Migrator for this.

We can then use the sqlx::test macro for whenever we need a PgPool in a test – it'll create a unique DB, run the migration files, and best of all drop the database once the test finishes.

So no more of these dang volumes:
Screenshot 2025-05-29 at 10 21 53

@juleswritescode juleswritescode requested a review from psteinroe May 28, 2025 08:09
@juleswritescode juleswritescode removed the request for review from psteinroe May 29, 2025 06:35
@juleswritescode juleswritescode marked this pull request as draft May 29, 2025 06:35
@juleswritescode juleswritescode changed the title refactor(test_db): expose postgres roles in testdb via mutexguard refactor(test_db): use sqlx::test May 29, 2025
@juleswritescode juleswritescode marked this pull request as ready for review May 29, 2025 08:23
@juleswritescode juleswritescode requested a review from psteinroe May 29, 2025 08:23
@juleswritescode juleswritescode changed the title refactor(test_db): use sqlx::test refactor(test_db): use sqlx::test instead May 29, 2025
Copy link
Collaborator

@psteinroe psteinroe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a really nice feature of sqlx!

@juleswritescode juleswritescode merged commit f6b752c into main May 31, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants