Skip to main content

Crate cruxmont_pg_test_macro

Crate cruxmont_pg_test_macro 

Source
Expand description

We can use the macro with the following:

#[db_test]
async fn test_create_username_conflict() {
    // SQLX_POSTGRES_POOL is the test DB pool provided by the macro
    let pool: &Pool<Postgres> = &*SQLX_POSTGRES_POOL;
    run_migrations(pool).await;

    let all_users = SqlxPostGresDescriptor::get_all_user_profiles(pool)
        .await
        .expect("get all users");

    assert_eq!(0, all_users.len());

    let new_user = gen_new_user_schema();

    // TestDbHandle is provided by the test macro and yields the SQLX_POSTGRES_POOL
    let outcome =
        create_customer::<SqlxPostGresDescriptor, TestDbHandle, TestConfig>(Json(new_user))
            .await;
    assert_eq!(201, outcome.into_response().status());
    let mut new_user = gen_new_user_schema();
    new_user.email = "another_email".into();
    insert_duplicate::<TestDbHandle>(new_user, "username already exists").await;
}

Attribute Macrosยง

pg_test