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

chore(launcher): use MigratorTrait explicitly in test database initialization macros #1153

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions libs/blockscout-service-launcher/src/test_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,13 @@ pub use database_name;
///
/// #[tokio::test]
/// async fn test() {
/// let db_guard = database!(migration_crate);
/// let db_guard = database!(Migrator);
/// // Perform operations with the database...
/// }
/// ```
///
/// The `migration_crate` parameter refers to the migration crate associated with the database.
/// The `Migrator` parameter refers to the struct implementing
/// `sea_orm_migration::MigratorTrait` associated with the database.
///
/// # Parameterized Tests
///
Expand All @@ -203,22 +204,22 @@ pub use database_name;
/// ```text
/// #[tokio::test]
/// async fn test_with_prefix() {
/// let db_guard = database!(migration_crate, "custom_prefix");
/// let db_guard = database!(Migrator, "custom_prefix");
/// // Perform operations with the database...
/// }
/// ```
#[macro_export]
macro_rules! database {
($migration_crate:ident) => {{
$crate::test_database::TestDbGuard::new::<$migration_crate::Migrator>(
($migrator:ty) => {{
$crate::test_database::TestDbGuard::new::<$migrator>(
&$crate::test_database::database_name!(),
)
.await
}};
($migration_crate:ident, $custom_prefix:expr) => {{
$crate::test_database::TestDbGuard::new::<$migration_crate::Migrator>(
$crate::test_database::database_name!($custom_prefix),
)
($migrator:ty, $custom_prefix:expr) => {{
$crate::test_database::TestDbGuard::new::<$migrator>($crate::test_database::database_name!(
$custom_prefix
))
.await
}};
}
Expand Down
Loading