feat: optionally provision test database
This commit is contained in:
parent
c1ac50c497
commit
e90b2d401c
7 changed files with 17 additions and 10 deletions
|
@ -31,6 +31,7 @@ mod tests {
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn test_postgres_create_verification_secret() {
|
async fn test_postgres_create_verification_secret() {
|
||||||
let settings = crate::settings::tests::get_settings().await;
|
let settings = crate::settings::tests::get_settings().await;
|
||||||
|
settings.create_db().await;
|
||||||
let db = super::DBOutPostgresAdapter::new(
|
let db = super::DBOutPostgresAdapter::new(
|
||||||
sqlx::postgres::PgPool::connect(&settings.database.url)
|
sqlx::postgres::PgPool::connect(&settings.database.url)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -39,6 +39,7 @@ mod tests {
|
||||||
let username = "batman";
|
let username = "batman";
|
||||||
let secret = "bsdasdf";
|
let secret = "bsdasdf";
|
||||||
let settings = crate::settings::tests::get_settings().await;
|
let settings = crate::settings::tests::get_settings().await;
|
||||||
|
settings.create_db().await;
|
||||||
let db = super::DBOutPostgresAdapter::new(
|
let db = super::DBOutPostgresAdapter::new(
|
||||||
sqlx::postgres::PgPool::connect(&settings.database.url)
|
sqlx::postgres::PgPool::connect(&settings.database.url)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -37,6 +37,7 @@ mod tests {
|
||||||
async fn test_postgres_email_exists() {
|
async fn test_postgres_email_exists() {
|
||||||
let email = "foo@exmaple.com";
|
let email = "foo@exmaple.com";
|
||||||
let settings = crate::settings::tests::get_settings().await;
|
let settings = crate::settings::tests::get_settings().await;
|
||||||
|
settings.create_db().await;
|
||||||
let db = super::DBOutPostgresAdapter::new(
|
let db = super::DBOutPostgresAdapter::new(
|
||||||
sqlx::postgres::PgPool::connect(&settings.database.url)
|
sqlx::postgres::PgPool::connect(&settings.database.url)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -42,6 +42,7 @@ mod tests {
|
||||||
let username = "batman";
|
let username = "batman";
|
||||||
let secret = "bsdasdf";
|
let secret = "bsdasdf";
|
||||||
let settings = crate::settings::tests::get_settings().await;
|
let settings = crate::settings::tests::get_settings().await;
|
||||||
|
settings.create_db().await;
|
||||||
let db = super::DBOutPostgresAdapter::new(
|
let db = super::DBOutPostgresAdapter::new(
|
||||||
sqlx::postgres::PgPool::connect(&settings.database.url)
|
sqlx::postgres::PgPool::connect(&settings.database.url)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -37,6 +37,7 @@ mod tests {
|
||||||
async fn test_postgres_username_exists() {
|
async fn test_postgres_username_exists() {
|
||||||
let username = "foo@exmaple.com";
|
let username = "foo@exmaple.com";
|
||||||
let settings = crate::settings::tests::get_settings().await;
|
let settings = crate::settings::tests::get_settings().await;
|
||||||
|
settings.create_db().await;
|
||||||
let db = super::DBOutPostgresAdapter::new(
|
let db = super::DBOutPostgresAdapter::new(
|
||||||
sqlx::postgres::PgPool::connect(&settings.database.url)
|
sqlx::postgres::PgPool::connect(&settings.database.url)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -46,6 +46,7 @@ mod tests {
|
||||||
let username = "batman";
|
let username = "batman";
|
||||||
let secret = "bsdasdf";
|
let secret = "bsdasdf";
|
||||||
let settings = crate::settings::tests::get_settings().await;
|
let settings = crate::settings::tests::get_settings().await;
|
||||||
|
settings.create_db().await;
|
||||||
let db = super::DBOutPostgresAdapter::new(
|
let db = super::DBOutPostgresAdapter::new(
|
||||||
sqlx::postgres::PgPool::connect(&settings.database.url)
|
sqlx::postgres::PgPool::connect(&settings.database.url)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -151,20 +151,21 @@ pub mod tests {
|
||||||
db_url.set_path(&GenerateRandomString.get_random(12));
|
db_url.set_path(&GenerateRandomString.get_random(12));
|
||||||
settings.database.url = db_url.to_string();
|
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
|
settings
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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) {
|
pub async fn drop_db(&self) {
|
||||||
crate::db::sqlx_postgres::PostgresDatabase
|
crate::db::sqlx_postgres::PostgresDatabase
|
||||||
.delete_database(&Url::parse(&self.database.url).unwrap())
|
.delete_database(&Url::parse(&self.database.url).unwrap())
|
||||||
|
|
Loading…
Reference in a new issue