Skip to content
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

Add ability to create new database per test case #1121

Open
Ghost-str opened this issue Jan 1, 2025 · 3 comments
Open

Add ability to create new database per test case #1121

Ghost-str opened this issue Jan 1, 2025 · 3 comments
Labels

Comments

@Ghost-str
Copy link

Ghost-str commented Jan 1, 2025

Description

Add ability to create and delete new database per test case for isolation purpose.

Expected Behavior

#[tokio::test]
async fn  test_name() {
   configure_insta!();
   let uuid = uuid();
   let appConfig= testing::create_test_database_with_postfix(&uuid).await.unwraup;
   let boot = testing::boot_test_with_custom_config::<App>(appConfig).await.unwrap;

   ... test body ....

   testing::remove_test_database_with_postfix(&uuid).await.unwraup;
}

Environment:

test

@kaplanelad
Copy link
Contributor

Could you please clarify the reasoning behind this request?

@Ghost-str
Copy link
Author

If you remove #[serial] for tests, then the tests begin to influence each other.
I think it would be more convenient if for each element of the infrastructure it was possible to isolate the application when running tests.
I think that over long distances this will help to perform tests faster

@NexVeridian
Copy link
Contributor

we should probably use #[sqlx::test]

it seems to be working ok for #1204

some info from here, Under the hood, this is [what sqlx does]:

It connects to the database specified in the DATABASE_URL environment variable.
It creates a new database with a random name.
(Optional) It runs all the migrations in the migrations directory.
It creates a connection pool to the new database.
It passes the connection pool to your test function.
It waits for the test to complete.
It deletes the database.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants