Fixing tests
This commit is contained in:
+29
-37
@@ -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
|
// Function to drop a database
|
||||||
pub async fn drop_database(
|
pub async fn drop_database(
|
||||||
template_pool: &sqlx::PgPool,
|
template_pool: &sqlx::PgPool,
|
||||||
@@ -73,16 +96,9 @@ mod db_mgr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
pub async fn migrations(pool: &sqlx::PgPool) {
|
pub async fn migrations(pool: &sqlx::PgPool) {
|
||||||
// Run migrations using the sqlx::migrate! macro
|
super::db::migrations(pool).await;
|
||||||
// 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");
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mod init {
|
mod init {
|
||||||
@@ -519,21 +535,7 @@ async fn test_update_contact_names() {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_create_message() {
|
async fn test_create_message() {
|
||||||
let tm_pool = db_mgr::get_pool().await.unwrap();
|
let (tm_pool, db_name, pool) = db_mgr::get_database_ready().await;
|
||||||
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 app = init::app(pool).await;
|
let app = init::app(pool).await;
|
||||||
|
|
||||||
// Send request
|
// Send request
|
||||||
@@ -560,20 +562,7 @@ async fn test_create_message() {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_get_message() {
|
async fn test_get_message() {
|
||||||
let tm_pool = db_mgr::get_pool().await.unwrap();
|
let (tm_pool, db_name, pool) = db_mgr::get_database_ready().await;
|
||||||
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 app = init::app(pool).await;
|
let app = init::app(pool).await;
|
||||||
let mut message_result: Option<textsender_models::message::Message> = None;
|
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;
|
let _ = db_mgr::drop_database(&tm_pool, &db_name).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
async fn test_schedule_message() {}
|
||||||
|
|||||||
Reference in New Issue
Block a user