diff --git a/tests/auth_tests.rs b/tests/auth_tests.rs index 947972b..538b79b 100644 --- a/tests/auth_tests.rs +++ b/tests/auth_tests.rs @@ -22,6 +22,28 @@ use axum::{ use tower::util::ServiceExt; // use testcontainers_modules::testcontainers::core::client:: +const TEST_DATABASE_URL_ENV: &str = "TEST_DATABASE_URL"; +const DEFAULT_TEST_DATABASE_URL: &str = + "postgres://icarus_op_test:password@localhost:5432/icarus_auth_test"; + +static SETUP: std::sync::Once = std::sync::Once::new(); + +async fn setup_database() -> sqlx::PgPool { + let database_url = std::env::var(TEST_DATABASE_URL_ENV) + .unwrap_or_else(|_| DEFAULT_TEST_DATABASE_URL.to_string()); + let pool = sqlx::PgPool::connect(&database_url) + .await + .expect("Failed to connect to test database"); + + let migrator = sqlx::migrate::Migrator::new(std::path::Path::new("./migrations")) + .await + .expect("Failed to create migrator"); + migrator.run(&pool).await.expect("Failed to run migrations"); + + // Seed here if needed + pool +} + /* async fn setup_test(pool: sqlx::PgPool) -> Router { Router::new()