fix: isolate test db
This commit is contained in:
parent
02e3e3f371
commit
67fa2c7381
1 changed files with 13 additions and 1 deletions
14
src/tests.rs
14
src/tests.rs
|
@ -24,6 +24,7 @@ use actix_web::{
|
||||||
};
|
};
|
||||||
use mktemp::Temp;
|
use mktemp::Temp;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
use url::Url;
|
||||||
|
|
||||||
use crate::ctx::api::v1::auth::{Login, Register};
|
use crate::ctx::api::v1::auth::{Login, Register};
|
||||||
use crate::ctx::api::v1::pages::AddSite;
|
use crate::ctx::api::v1::pages::AddSite;
|
||||||
|
@ -40,6 +41,15 @@ pub async fn get_ctx() -> (Temp, Arc<Ctx>) {
|
||||||
// mktemp::Temp is returned because the temp directory created
|
// mktemp::Temp is returned because the temp directory created
|
||||||
// is removed once the variable goes out of scope
|
// is removed once the variable goes out of scope
|
||||||
let mut settings = Settings::new().unwrap();
|
let mut settings = Settings::new().unwrap();
|
||||||
|
let mut db_url = Url::parse(&settings.database.url).unwrap();
|
||||||
|
db_url.set_path(&crate::utils::get_random(8));
|
||||||
|
settings.database.url = db_url.to_string();
|
||||||
|
|
||||||
|
use sqlx::migrate::MigrateDatabase;
|
||||||
|
// sqlx::Postgres::create_database(&settings.database.url).await.unwrap();
|
||||||
|
sqlx::postgres::Postgres::create_database(&settings.database.url)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let tmp_dir = Temp::new_dir().unwrap();
|
let tmp_dir = Temp::new_dir().unwrap();
|
||||||
println!("[log] Test temp directory: {}", tmp_dir.to_str().unwrap());
|
println!("[log] Test temp directory: {}", tmp_dir.to_str().unwrap());
|
||||||
|
@ -48,8 +58,10 @@ pub async fn get_ctx() -> (Temp, Arc<Ctx>) {
|
||||||
settings.init();
|
settings.init();
|
||||||
println!("[log] Initialzing settings again with test config");
|
println!("[log] Initialzing settings again with test config");
|
||||||
settings.init();
|
settings.init();
|
||||||
|
let ctx = Ctx::new(settings).await;
|
||||||
|
ctx.db.migrate().await.unwrap();
|
||||||
|
|
||||||
(tmp_dir, Ctx::new(settings).await)
|
(tmp_dir, ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code, clippy::upper_case_acronyms)]
|
#[allow(dead_code, clippy::upper_case_acronyms)]
|
||||||
|
|
Loading…
Reference in a new issue