Attribute Macro test

Source
#[test]
Expand description

Marks async test function that exposes database pool to its scope

§Macro attributes:

  • variable: Variable of the PgPool to be exposed to the function scope (mandatory)
  • other_dir_migrations: Path to SQLX other_dir_migrations directory for the specified pool (falls back to default ./migrations directory if left out)
  • skip_migrations: If present, doesn’t run any other_dir_migrations
#[sqlx_database_tester::test(
    pool(variable = "default_migrated_pool"),
    pool(variable = "migrated_pool", migrations = "./other_dir_migrations"),
    pool(variable = "empty_db_pool",
         transaction_variable = "empty_db_transaction",
         skip_migrations),
)]
async fn test_server_sta_rt() {
    let migrated_pool_tables = sqlx::query!("SELECT * FROM pg_catalog.pg_tables")
        .fetch_all(&migrated_pool)
        .await
        .unwrap();
    let empty_pool_tables = sqlx::query!("SELECT * FROM pg_catalog.pg_tables")
        .fetch_all(&migrated_pool)
        .await
        .unwrap();
    println!("Migrated pool tables: \n {:#?}", migrated_pool_tables);
    println!("Empty pool tables: \n {:#?}", empty_pool_tables);
}