Skip to content

Commit

Permalink
feat(launcher): add test database initialization macros
Browse files Browse the repository at this point in the history
  • Loading branch information
rimrakhimov committed Dec 2, 2024
1 parent ec1c755 commit 20dc5fb
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions libs/blockscout-service-launcher/src/test_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,31 @@ impl Deref for TestDbGuard {
&self.conn_with_db
}
}

#[macro_export]
macro_rules! database_name {
() => {
format!("{}_{}_{}", file!(), line!(), column!())
};
($custom_suffix:expr) => {
format!("{}_{}_{}_{}", file!(), line!(), column!(), $custom_suffix)
};
}
pub use database_name;

#[macro_export]
macro_rules! database {
($migration_crate:ident) => {{
$crate::test_database::TestDbGuard::new::<$migration_crate::Migrator>(
&$crate::test_database::database_name!(),
)
.await
}};
($migration_crate:ident, $custom_suffix:expr) => {{
$crate::test_database::TestDbGuard::new::<$migration_crate::Migrator>(
$crate::test_database::database_name!($custom_suffix),
)
.await
}};
}
pub use database;

0 comments on commit 20dc5fb

Please sign in to comment.