From e01585c9e71c68aee33556971b508ee9c1781b28 Mon Sep 17 00:00:00 2001 From: Sam Samai Date: Fri, 6 Aug 2021 22:27:03 +1000 Subject: [PATCH] Add runtime configs to tests and clean up --- tests/bakery_chain_tests.rs | 6 ++++-- tests/basic.rs | 2 +- tests/query_tests.rs | 34 +++++++++++++++++++++++++--------- tests/relational_tests.rs | 22 ++++++++++++++++------ tests/sequential_op_tests.rs | 11 +++++++++-- 5 files changed, 55 insertions(+), 20 deletions(-) diff --git a/tests/bakery_chain_tests.rs b/tests/bakery_chain_tests.rs index 70b576e9..6410a663 100644 --- a/tests/bakery_chain_tests.rs +++ b/tests/bakery_chain_tests.rs @@ -6,8 +6,10 @@ pub use common::{bakery_chain::*, setup::*, TestContext}; mod crud; // Run the test locally: -// DATABASE_URL="mysql://root:@localhost" cargo test --features sqlx-mysql --test bakery_chain_tests -#[async_std::test] +// DATABASE_URL="mysql://root:@localhost" cargo test --features sqlx-mysql,runtime-async-std --test bakery_chain_tests +#[cfg_attr(feature = "runtime-async-std", async_std::test)] +#[cfg_attr(feature = "runtime-actix", actix_rt::test)] +#[cfg_attr(feature = "runtime-tokio", tokio::test)] #[cfg(any( feature = "sqlx-mysql", feature = "sqlx-sqlite", diff --git a/tests/basic.rs b/tests/basic.rs index 797d3b90..af724b10 100644 --- a/tests/basic.rs +++ b/tests/basic.rs @@ -1,7 +1,7 @@ #[allow(unused_imports)] use sea_orm::{entity::*, error::*, sea_query, tests_cfg::*, Database, DbConn}; -// cargo test --test basic -- --nocapture +// DATABASE_URL="sqlite::memory:" cargo test --features sqlx-sqlit,runtime-async-std --test basic #[cfg_attr(feature = "runtime-async-std", async_std::test)] #[cfg_attr(feature = "runtime-actix", actix_rt::test)] #[cfg_attr(feature = "runtime-tokio", tokio::test)] diff --git a/tests/query_tests.rs b/tests/query_tests.rs index 7b605a7a..2791f908 100644 --- a/tests/query_tests.rs +++ b/tests/query_tests.rs @@ -5,8 +5,10 @@ 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] +// DATABASE_URL="mysql://root:@localhost" cargo test --features sqlx-mysql,runtime-async-std --test query_tests +#[cfg_attr(feature = "runtime-async-std", async_std::test)] +#[cfg_attr(feature = "runtime-actix", actix_rt::test)] +#[cfg_attr(feature = "runtime-tokio", tokio::test)] #[cfg(any( feature = "sqlx-mysql", feature = "sqlx-sqlite", @@ -21,7 +23,9 @@ pub async fn find_one_with_no_result() { ctx.delete().await; } -#[async_std::test] +#[cfg_attr(feature = "runtime-async-std", async_std::test)] +#[cfg_attr(feature = "runtime-actix", actix_rt::test)] +#[cfg_attr(feature = "runtime-tokio", tokio::test)] #[cfg(any( feature = "sqlx-mysql", feature = "sqlx-sqlite", @@ -46,7 +50,9 @@ pub async fn find_one_with_result() { ctx.delete().await; } -#[async_std::test] +#[cfg_attr(feature = "runtime-async-std", async_std::test)] +#[cfg_attr(feature = "runtime-actix", actix_rt::test)] +#[cfg_attr(feature = "runtime-tokio", tokio::test)] #[cfg(any( feature = "sqlx-mysql", feature = "sqlx-sqlite", @@ -61,7 +67,9 @@ pub async fn find_by_id_with_no_result() { ctx.delete().await; } -#[async_std::test] +#[cfg_attr(feature = "runtime-async-std", async_std::test)] +#[cfg_attr(feature = "runtime-actix", actix_rt::test)] +#[cfg_attr(feature = "runtime-tokio", tokio::test)] #[cfg(any( feature = "sqlx-mysql", feature = "sqlx-sqlite", @@ -90,7 +98,9 @@ pub async fn find_by_id_with_result() { ctx.delete().await; } -#[async_std::test] +#[cfg_attr(feature = "runtime-async-std", async_std::test)] +#[cfg_attr(feature = "runtime-actix", actix_rt::test)] +#[cfg_attr(feature = "runtime-tokio", tokio::test)] #[cfg(any( feature = "sqlx-mysql", feature = "sqlx-sqlite", @@ -105,7 +115,9 @@ pub async fn find_all_with_no_result() { ctx.delete().await; } -#[async_std::test] +#[cfg_attr(feature = "runtime-async-std", async_std::test)] +#[cfg_attr(feature = "runtime-actix", actix_rt::test)] +#[cfg_attr(feature = "runtime-tokio", tokio::test)] #[cfg(any( feature = "sqlx-mysql", feature = "sqlx-sqlite", @@ -139,7 +151,9 @@ pub async fn find_all_with_result() { ctx.delete().await; } -#[async_std::test] +#[cfg_attr(feature = "runtime-async-std", async_std::test)] +#[cfg_attr(feature = "runtime-actix", actix_rt::test)] +#[cfg_attr(feature = "runtime-tokio", tokio::test)] #[cfg(any( feature = "sqlx-mysql", feature = "sqlx-sqlite", @@ -177,7 +191,9 @@ pub async fn find_all_filter_no_result() { ctx.delete().await; } -#[async_std::test] +#[cfg_attr(feature = "runtime-async-std", async_std::test)] +#[cfg_attr(feature = "runtime-actix", actix_rt::test)] +#[cfg_attr(feature = "runtime-tokio", tokio::test)] #[cfg(any( feature = "sqlx-mysql", feature = "sqlx-sqlite", diff --git a/tests/relational_tests.rs b/tests/relational_tests.rs index 0025db50..85fdee41 100644 --- a/tests/relational_tests.rs +++ b/tests/relational_tests.rs @@ -7,8 +7,10 @@ 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] +// DATABASE_URL="mysql://root:@localhost" cargo test --features sqlx-mysql,runtime-async-std --test relational_tests +#[cfg_attr(feature = "runtime-async-std", async_std::test)] +#[cfg_attr(feature = "runtime-actix", actix_rt::test)] +#[cfg_attr(feature = "runtime-tokio", tokio::test)] #[cfg(any( feature = "sqlx-mysql", feature = "sqlx-sqlite", @@ -89,7 +91,9 @@ pub async fn left_join() { ctx.delete().await; } -#[async_std::test] +#[cfg_attr(feature = "runtime-async-std", async_std::test)] +#[cfg_attr(feature = "runtime-actix", actix_rt::test)] +#[cfg_attr(feature = "runtime-tokio", tokio::test)] #[cfg(any(feature = "sqlx-mysql", feature = "sqlx-postgres"))] pub async fn right_join() { let ctx = TestContext::new("test_right_join").await; @@ -170,7 +174,9 @@ pub async fn right_join() { ctx.delete().await; } -#[async_std::test] +#[cfg_attr(feature = "runtime-async-std", async_std::test)] +#[cfg_attr(feature = "runtime-actix", actix_rt::test)] +#[cfg_attr(feature = "runtime-tokio", tokio::test)] #[cfg(any( feature = "sqlx-mysql", feature = "sqlx-sqlite", @@ -259,7 +265,9 @@ pub async fn inner_join() { ctx.delete().await; } -#[async_std::test] +#[cfg_attr(feature = "runtime-async-std", async_std::test)] +#[cfg_attr(feature = "runtime-actix", actix_rt::test)] +#[cfg_attr(feature = "runtime-tokio", tokio::test)] #[cfg(any( feature = "sqlx-mysql", feature = "sqlx-sqlite", @@ -363,7 +371,9 @@ pub async fn group_by() { ctx.delete().await; } -#[async_std::test] +#[cfg_attr(feature = "runtime-async-std", async_std::test)] +#[cfg_attr(feature = "runtime-actix", actix_rt::test)] +#[cfg_attr(feature = "runtime-tokio", tokio::test)] #[cfg(any( feature = "sqlx-mysql", feature = "sqlx-sqlite", diff --git a/tests/sequential_op_tests.rs b/tests/sequential_op_tests.rs index d21e1c66..d734ceac 100644 --- a/tests/sequential_op_tests.rs +++ b/tests/sequential_op_tests.rs @@ -8,8 +8,10 @@ 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 sequential_op_tests -#[async_std::test] +// DATABASE_URL="mysql://root:@localhost" cargo test --features sqlx-mysql,runtime-async-std --test sequential_op_tests +#[cfg_attr(feature = "runtime-async-std", async_std::test)] +#[cfg_attr(feature = "runtime-actix", actix_rt::test)] +#[cfg_attr(feature = "runtime-tokio", tokio::test)] #[cfg(any(feature = "sqlx-mysql", feature = "sqlx-postgres"))] pub async fn test_multiple_operations() { let ctx = TestContext::new("multiple_sequential_operations").await; @@ -27,6 +29,7 @@ pub async fn test_multiple_operations() { ctx.delete().await; } +#[cfg(any(feature = "sqlx-mysql", feature = "sqlx-postgres"))] async fn init_setup(db: &DatabaseConnection) { let bakery = bakery::ActiveModel { name: Set("SeaSide Bakery".to_owned()), @@ -125,6 +128,7 @@ async fn init_setup(db: &DatabaseConnection) { .expect("could not insert order"); } +#[cfg(any(feature = "sqlx-mysql", feature = "sqlx-postgres"))] async fn find_baker_least_sales(db: &DatabaseConnection) -> Option { #[cfg(feature = "sqlx-postgres")] type Type = i64; @@ -187,6 +191,7 @@ async fn find_baker_least_sales(db: &DatabaseConnection) -> Option .unwrap() } +#[cfg(any(feature = "sqlx-mysql", feature = "sqlx-postgres"))] async fn create_cake(db: &DatabaseConnection, baker: baker::Model) -> Option { let new_cake = cake::ActiveModel { name: Set("New Cake".to_owned()), @@ -219,6 +224,7 @@ async fn create_cake(db: &DatabaseConnection, baker: baker::Model) -> Option