Add runtime configs to tests and clean up

This commit is contained in:
Sam Samai 2021-08-06 22:27:03 +10:00
parent e7d2899019
commit e01585c9e7
5 changed files with 55 additions and 20 deletions

View File

@ -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",

View File

@ -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)]

View File

@ -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",

View File

@ -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",

View File

@ -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<baker::Model> {
#[cfg(feature = "sqlx-postgres")]
type Type = i64;
@ -187,6 +191,7 @@ async fn find_baker_least_sales(db: &DatabaseConnection) -> Option<baker::Model>
.unwrap()
}
#[cfg(any(feature = "sqlx-mysql", feature = "sqlx-postgres"))]
async fn create_cake(db: &DatabaseConnection, baker: baker::Model) -> Option<cake::Model> {
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<cak
.unwrap()
}
#[cfg(any(feature = "sqlx-mysql", feature = "sqlx-postgres"))]
async fn create_order(db: &DatabaseConnection, cake: cake::Model) {
let another_customer = customer::ActiveModel {
name: Set("John".to_owned()),
@ -252,6 +258,7 @@ async fn create_order(db: &DatabaseConnection, cake: cake::Model) {
.expect("could not insert order");
}
#[cfg(any(feature = "sqlx-mysql", feature = "sqlx-postgres"))]
pub async fn test_delete_bakery(db: &DatabaseConnection) {
let initial_bakeries = Bakery::find().all(db).await.unwrap().len();