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

Merged
merged 7 commits into from
Dec 5, 2024

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?

@rimrakhimov rimrakhimov force-pushed the rimrakhimov/launcher/add-database-macros branch from 7caa9d3 to d086893 Compare December 4, 2024 12:15
@rimrakhimov rimrakhimov merged commit a02d7de into main Dec 5, 2024
2 checks passed
@rimrakhimov rimrakhimov deleted the rimrakhimov/launcher/add-database-macros branch December 5, 2024 13:06
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.

3 participants