Fixing tests
Rust Build / Rustfmt (pull_request) Successful in 27s
Rust Build / Test Suite (pull_request) Successful in 59s

This commit is contained in:
2026-06-17 17:16:56 -04:00
parent a78078bddd
commit aff351915c
+29 -37
View File
@@ -43,6 +43,29 @@ mod db_mgr {
}
}
pub async fn get_database_ready() -> (
sqlx::Pool<sqlx::Postgres>,
String,
sqlx::Pool<sqlx::Postgres>,
) {
let tm_pool = get_pool().await.unwrap();
let db_name = generate_db_name().await;
match create_database(&tm_pool, &db_name).await {
Ok(_) => {
println!("Success");
}
Err(err) => {
assert!(false, "Error: {:?}", err);
}
}
let pool = connect_to_db(&db_name).await.unwrap();
migrations(&pool).await;
// db::migrations(&pool).await;
(tm_pool, db_name, pool)
}
// Function to drop a database
pub async fn drop_database(
template_pool: &sqlx::PgPool,
@@ -73,16 +96,9 @@ mod db_mgr {
}
}
/*
pub async fn migrations(pool: &sqlx::PgPool) {
// Run migrations using the sqlx::migrate! macro
// Assumes your test migrations are in a ./test_migrations folder relative to Cargo.toml
sqlx::migrate!("./migrations")
.run(pool)
.await
.expect("Failed to run migrations");
super::db::migrations(pool).await;
}
*/
}
mod init {
@@ -519,21 +535,7 @@ async fn test_update_contact_names() {
#[tokio::test]
async fn test_create_message() {
let tm_pool = db_mgr::get_pool().await.unwrap();
let db_name = db_mgr::generate_db_name().await;
match db_mgr::create_database(&tm_pool, &db_name).await {
Ok(_) => {
println!("Success");
}
Err(err) => {
assert!(false, "Error: {:?}", err);
}
}
let pool = db_mgr::connect_to_db(&db_name).await.unwrap();
db::migrations(&pool).await;
let (tm_pool, db_name, pool) = db_mgr::get_database_ready().await;
let app = init::app(pool).await;
// Send request
@@ -560,20 +562,7 @@ async fn test_create_message() {
#[tokio::test]
async fn test_get_message() {
let tm_pool = db_mgr::get_pool().await.unwrap();
let db_name = db_mgr::generate_db_name().await;
match db_mgr::create_database(&tm_pool, &db_name).await {
Ok(_) => {
println!("Success");
}
Err(err) => {
assert!(false, "Error: {:?}", err);
}
}
let pool = db_mgr::connect_to_db(&db_name).await.unwrap();
db::migrations(&pool).await;
let (tm_pool, db_name, pool) = db_mgr::get_database_ready().await;
let app = init::app(pool).await;
let mut message_result: Option<textsender_models::message::Message> = None;
@@ -617,3 +606,6 @@ async fn test_get_message() {
let _ = db_mgr::drop_database(&tm_pool, &db_name).await;
}
#[tokio::test]
async fn test_schedule_message() {}