#![allow(unused)] use microrm::prelude::*; pub fn open_test_db_helper( identifier: &'static str, ) -> (microrm::ConnectionPool, DB) { let pool = open_test_pool_helper(identifier); let db = DB::default(); db.install(&mut pool.acquire().expect("couldn't acquire lease")) .expect("couldn't install schema"); (pool, db) } pub fn open_test_pool_helper(identifier: &'static str) -> microrm::ConnectionPool { let path = test_db_path(identifier); log::info!("path to test database: {path}"); let _ = std::fs::remove_file(path.as_str()); let pool = microrm::ConnectionPool::new(path.as_str()).expect("couldn't connect to database"); pool } fn test_db_path(identifier: &'static str) -> String { let path = format!( "{tmpdir}/{identifier}.db", tmpdir = std::env!("CARGO_TARGET_TMPDIR"), ); path.replace("::", "_") } mod macros { macro_rules! open_test_db { () => {{ use stdext::function_name; $crate::common::open_test_db_helper(function_name!()) }}; } macro_rules! open_test_pool { () => {{ use stdext::function_name; $crate::common::open_test_pool_helper(function_name!()) }}; } pub(crate) use open_test_db; pub(crate) use open_test_pool; } pub(crate) use macros::open_test_db; pub(crate) use macros::open_test_pool;