Macro with_test_db

Source
macro_rules! with_test_db {
    ($f:expr) => { ... };
}
Expand description

Creates a new PostgreSQL test database and executes the provided test function.

This macro handles the creation of a temporary database, executes the test function, and ensures proper cleanup after the test completes.

§Arguments

  • $f - A function that takes a TestDatabase and returns a future

§Example

#[tokio::test]
async fn test_users() {
    with_test_db(|db| async move {
        db.setup(|mut conn| async move {
            conn.execute("CREATE TABLE users (id SERIAL PRIMARY KEY)").await?;
            Ok(())
        }).await?;
        Ok(())
    }).await;
}