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

feat(launcher): add test database initialization helping macros #1135

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

rimrakhimov
Copy link
Member

@rimrakhimov rimrakhimov commented Dec 2, 2024

Helps when initializing database inside tests. Allows not to provide the test case name as it automatically uses the place that function is defined instead.

Note!!: using it with rstest parameterized test cases (https://docs.rs/rstest/latest/rstest/attr.rstest.html#test-parametrized-cases) results in the same database name for all cases. In such cases, you have to manually provide some meaningful suffix as a database! or database_name! argument (the second macros branches)

Can be used inside test in the following way (the migration crate has a name migration_crate):

use blockscout_service_launcher::test_database::database;
...
#[tokio::test]
async fn test() {
    let db_guard = database!(migration_crate);
    ...
}

@bragov4ik
Copy link
Contributor

Let's add the note and usage example to the macro documentation?

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