diff --git a/src/identity/adapters/output/db/postgres/create_verification_secret.rs b/src/identity/adapters/output/db/postgres/create_verification_secret.rs index 08287be..b9542ca 100644 --- a/src/identity/adapters/output/db/postgres/create_verification_secret.rs +++ b/src/identity/adapters/output/db/postgres/create_verification_secret.rs @@ -31,6 +31,7 @@ mod tests { #[actix_rt::test] async fn test_postgres_create_verification_secret() { let settings = crate::settings::tests::get_settings().await; + settings.create_db().await; let db = super::DBOutPostgresAdapter::new( sqlx::postgres::PgPool::connect(&settings.database.url) .await diff --git a/src/identity/adapters/output/db/postgres/delete_verification_secret.rs b/src/identity/adapters/output/db/postgres/delete_verification_secret.rs index 9433e2b..a75728e 100644 --- a/src/identity/adapters/output/db/postgres/delete_verification_secret.rs +++ b/src/identity/adapters/output/db/postgres/delete_verification_secret.rs @@ -39,6 +39,7 @@ mod tests { let username = "batman"; let secret = "bsdasdf"; let settings = crate::settings::tests::get_settings().await; + settings.create_db().await; let db = super::DBOutPostgresAdapter::new( sqlx::postgres::PgPool::connect(&settings.database.url) .await diff --git a/src/identity/adapters/output/db/postgres/email_exists.rs b/src/identity/adapters/output/db/postgres/email_exists.rs index 19691ae..c4cf50f 100644 --- a/src/identity/adapters/output/db/postgres/email_exists.rs +++ b/src/identity/adapters/output/db/postgres/email_exists.rs @@ -37,6 +37,7 @@ mod tests { async fn test_postgres_email_exists() { let email = "foo@exmaple.com"; let settings = crate::settings::tests::get_settings().await; + settings.create_db().await; let db = super::DBOutPostgresAdapter::new( sqlx::postgres::PgPool::connect(&settings.database.url) .await diff --git a/src/identity/adapters/output/db/postgres/get_verification_secret.rs b/src/identity/adapters/output/db/postgres/get_verification_secret.rs index cb6deca..56dcc77 100644 --- a/src/identity/adapters/output/db/postgres/get_verification_secret.rs +++ b/src/identity/adapters/output/db/postgres/get_verification_secret.rs @@ -42,6 +42,7 @@ mod tests { let username = "batman"; let secret = "bsdasdf"; let settings = crate::settings::tests::get_settings().await; + settings.create_db().await; let db = super::DBOutPostgresAdapter::new( sqlx::postgres::PgPool::connect(&settings.database.url) .await diff --git a/src/identity/adapters/output/db/postgres/username_exists.rs b/src/identity/adapters/output/db/postgres/username_exists.rs index 3e5b04e..46e8598 100644 --- a/src/identity/adapters/output/db/postgres/username_exists.rs +++ b/src/identity/adapters/output/db/postgres/username_exists.rs @@ -37,6 +37,7 @@ mod tests { async fn test_postgres_username_exists() { let username = "foo@exmaple.com"; let settings = crate::settings::tests::get_settings().await; + settings.create_db().await; let db = super::DBOutPostgresAdapter::new( sqlx::postgres::PgPool::connect(&settings.database.url) .await diff --git a/src/identity/adapters/output/db/postgres/verification_secret_exists.rs b/src/identity/adapters/output/db/postgres/verification_secret_exists.rs index 4a43d81..052b724 100644 --- a/src/identity/adapters/output/db/postgres/verification_secret_exists.rs +++ b/src/identity/adapters/output/db/postgres/verification_secret_exists.rs @@ -46,6 +46,7 @@ mod tests { let username = "batman"; let secret = "bsdasdf"; let settings = crate::settings::tests::get_settings().await; + settings.create_db().await; let db = super::DBOutPostgresAdapter::new( sqlx::postgres::PgPool::connect(&settings.database.url) .await diff --git a/src/settings/mod.rs b/src/settings/mod.rs index 441d401..a1e7f46 100644 --- a/src/settings/mod.rs +++ b/src/settings/mod.rs @@ -151,20 +151,21 @@ pub mod tests { db_url.set_path(&GenerateRandomString.get_random(12)); settings.database.url = db_url.to_string(); - crate::db::sqlx_postgres::PostgresDatabase - .create_database(&db_url) - .await; - let db = Postgres::new( - sqlx::postgres::PgPool::connect(&settings.database.url) - .await - .unwrap(), - ); - db.migrate().await; - settings } impl Settings { + pub async fn create_db(&self) { + crate::db::sqlx_postgres::PostgresDatabase + .create_database(&Url::parse(&self.database.url).unwrap()) + .await; + let db = Postgres::new( + sqlx::postgres::PgPool::connect(&self.database.url) + .await + .unwrap(), + ); + db.migrate().await; + } pub async fn drop_db(&self) { crate::db::sqlx_postgres::PostgresDatabase .delete_database(&Url::parse(&self.database.url).unwrap())