fixed compatibility layer to old tests git status REMOVE IN THE FUTURE
This commit is contained in:
@@ -1,24 +1,22 @@
|
|||||||
// tests/common/mod.rs
|
// tests/common/mod.rs
|
||||||
|
|
||||||
use dotenvy::dotenv;
|
use dotenvy::dotenv;
|
||||||
// --- CHANGE 1: Add Alphanumeric to the use statement ---
|
|
||||||
use rand::distr::Alphanumeric;
|
use rand::distr::Alphanumeric;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use sqlx::{postgres::PgPoolOptions, Connection, Executor, PgConnection, PgPool};
|
use sqlx::{postgres::PgPoolOptions, Connection, Executor, PgConnection, PgPool};
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
// (The get_database_url and get_root_connection functions remain the same)
|
|
||||||
fn get_database_url() -> String {
|
fn get_database_url() -> String {
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
env::var("TEST_DATABASE_URL").expect("TEST_DATABASE_URL must be set")
|
env::var("TEST_DATABASE_URL").expect("TEST_DATABASE_URL must be set")
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_root_connection() -> PgConnection {
|
async fn get_root_connection() -> PgConnection {
|
||||||
PgConnection::connect(&get_database_url())
|
PgConnection::connect(&get_database_url())
|
||||||
.await
|
.await
|
||||||
.expect("Failed to create root connection to test database")
|
.expect("Failed to create root connection to test database")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// The primary test setup function.
|
/// The primary test setup function.
|
||||||
/// Creates a new, unique schema and returns a connection pool that is scoped to that schema.
|
/// Creates a new, unique schema and returns a connection pool that is scoped to that schema.
|
||||||
/// This is the key to test isolation.
|
/// This is the key to test isolation.
|
||||||
@@ -56,7 +54,6 @@ pub async fn setup_isolated_db() -> PgPool {
|
|||||||
let schema_name = schema_name.clone();
|
let schema_name = schema_name.clone();
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
conn.execute(format!("SET search_path TO \"{}\", \"default\", \"public\"", schema_name).as_str())
|
conn.execute(format!("SET search_path TO \"{}\", \"default\", \"public\"", schema_name).as_str())
|
||||||
|
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
@@ -83,3 +80,9 @@ pub async fn setup_isolated_db() -> PgPool {
|
|||||||
|
|
||||||
pool
|
pool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Compatibility alias for the old function name
|
||||||
|
/// This allows existing tests to continue working without modification
|
||||||
|
pub async fn setup_test_db() -> PgPool {
|
||||||
|
setup_isolated_db().await
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// tests/mod.rs
|
// tests/mod.rs
|
||||||
// pub mod adresar;
|
pub mod adresar;
|
||||||
// pub mod tables_data;
|
// pub mod tables_data;
|
||||||
pub mod common;
|
pub mod common;
|
||||||
pub mod table_definition;
|
pub mod table_definition;
|
||||||
|
|||||||
Reference in New Issue
Block a user