From 1c3e1b410b61e93a0c403b537ea7b849aee9ac45 Mon Sep 17 00:00:00 2001 From: Sam Samai Date: Sat, 31 Jul 2021 16:50:04 +1000 Subject: [PATCH] Use DATABASE_URL env variable for bakery_chain_tests --- tests/bakery_chain_tests.rs | 18 ++++++++++-------- tests/query_tests.rs | 11 ++--------- tests/relational_tests.rs | 4 ++-- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/tests/bakery_chain_tests.rs b/tests/bakery_chain_tests.rs index 8c52ca2a..70b576e9 100644 --- a/tests/bakery_chain_tests.rs +++ b/tests/bakery_chain_tests.rs @@ -5,16 +5,18 @@ pub use common::{bakery_chain::*, setup::*, TestContext}; mod crud; -// cargo test --test bakery_chain_tests -- --nocapture +// Run the test locally: +// DATABASE_URL="mysql://root:@localhost" cargo test --features sqlx-mysql --test bakery_chain_tests #[async_std::test] -#[cfg(feature = "sqlx-mysql")] +#[cfg(any( + feature = "sqlx-mysql", + feature = "sqlx-sqlite", + feature = "sqlx-postgres" +))] async fn main() { - let base_url = "mysql://root:@localhost"; - let db_name = "bakery_chain_schema_crud_tests"; - - let db: DatabaseConnection = common::setup::setup(base_url, db_name).await; - create_entities(&db).await; - common::setup::tear_down(base_url, db_name).await; + let ctx = TestContext::new("bakery_chain_schema_crud_tests").await; + create_entities(&ctx.db).await; + ctx.delete().await; } async fn create_entities(db: &DatabaseConnection) { diff --git a/tests/query_tests.rs b/tests/query_tests.rs index fbe77ba2..2626ee0b 100644 --- a/tests/query_tests.rs +++ b/tests/query_tests.rs @@ -1,17 +1,17 @@ -// cargo test --test query_tests -- --nocapture use sea_orm::entity::*; use sea_orm::QueryFilter; pub mod common; pub use common::{bakery_chain::*, setup::*, TestContext}; +// Run the test locally: +// DATABASE_URL="mysql://root:@localhost" cargo test --features sqlx-mysql --test query_tests #[async_std::test] #[cfg(any( feature = "sqlx-mysql", feature = "sqlx-sqlite", feature = "sqlx-postgres" ))] - pub async fn find_one_with_no_result() { let ctx = TestContext::new("find_one_with_no_result").await; @@ -27,7 +27,6 @@ pub async fn find_one_with_no_result() { feature = "sqlx-sqlite", feature = "sqlx-postgres" ))] -#[cfg(feature = "sqlx-mysql")] pub async fn find_one_with_result() { let ctx = TestContext::new("find_one_with_result").await; @@ -53,7 +52,6 @@ pub async fn find_one_with_result() { feature = "sqlx-sqlite", feature = "sqlx-postgres" ))] -#[cfg(feature = "sqlx-mysql")] pub async fn find_by_id_with_no_result() { let ctx = TestContext::new("find_by_id_with_no_result").await; @@ -69,7 +67,6 @@ pub async fn find_by_id_with_no_result() { feature = "sqlx-sqlite", feature = "sqlx-postgres" ))] -#[cfg(feature = "sqlx-mysql")] pub async fn find_by_id_with_result() { let ctx = TestContext::new("find_by_id_with_result").await; @@ -99,7 +96,6 @@ pub async fn find_by_id_with_result() { feature = "sqlx-sqlite", feature = "sqlx-postgres" ))] -#[cfg(feature = "sqlx-mysql")] pub async fn find_all_with_no_result() { let ctx = TestContext::new("find_all_with_no_result").await; @@ -115,7 +111,6 @@ pub async fn find_all_with_no_result() { feature = "sqlx-sqlite", feature = "sqlx-postgres" ))] -#[cfg(feature = "sqlx-mysql")] pub async fn find_all_with_result() { let ctx = TestContext::new("find_all_with_result").await; @@ -150,7 +145,6 @@ pub async fn find_all_with_result() { feature = "sqlx-sqlite", feature = "sqlx-postgres" ))] -#[cfg(feature = "sqlx-mysql")] pub async fn find_all_filter_no_result() { let ctx = TestContext::new("find_all_filter_no_result").await; @@ -189,7 +183,6 @@ pub async fn find_all_filter_no_result() { feature = "sqlx-sqlite", feature = "sqlx-postgres" ))] -#[cfg(feature = "sqlx-mysql")] pub async fn find_all_filter_with_results() { let ctx = TestContext::new("find_all_filter_with_results").await; diff --git a/tests/relational_tests.rs b/tests/relational_tests.rs index 6c00e421..147f5344 100644 --- a/tests/relational_tests.rs +++ b/tests/relational_tests.rs @@ -1,5 +1,3 @@ -// cargo test --test realtional_tests -- --nocapture - use chrono::offset::Utc; use rust_decimal::prelude::*; use rust_decimal_macros::dec; @@ -8,6 +6,8 @@ use sea_orm::{entity::*, query::*, FromQueryResult}; pub mod common; pub use common::{bakery_chain::*, setup::*, TestContext}; +// Run the test locally: +// DATABASE_URL="mysql://root:@localhost" cargo test --features sqlx-mysql --test realtional_tests #[async_std::test] #[cfg(any( feature = "sqlx-mysql",