diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1950361..a5b99ee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,7 +41,7 @@ jobs: - name: Start dynamodb-local run: sudo docker run --name dynamodb -d -p 8000:8000 amazon/dynamodb-local:latest -jar DynamoDBLocal.jar -port 8000 - name: cargo test - run: cargo test --workspace + run: cargo test --workspace --all-features gen-examples: needs: check diff --git a/tests/client/Cargo.toml b/tests/client/Cargo.toml index ad506c7..9c7c435 100644 --- a/tests/client/Cargo.toml +++ b/tests/client/Cargo.toml @@ -4,7 +4,16 @@ version = "0.1.0" edition = "2021" publish = false -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[features] +default = ["sqlite"] +sqlite = [ + "dep:toasty-sqlite", +] +dynamodb = [ + "dep:toasty-dynamodb", + "dep:aws-config", + "dep:aws-sdk-dynamodb", +] [dependencies] async-trait = "0.1" @@ -13,12 +22,12 @@ toasty-core = { path = "../../src/core" } toasty-macros = { path = "../../src/macros" } # Sqlite driver -toasty-sqlite = { path = "../../src/db/sqlite" } +toasty-sqlite = { path = "../../src/db/sqlite", optional = true } # DyanmoDB driver -toasty-dynamodb = { path = "../../src/db/ddb" } -aws-config = "1" -aws-sdk-dynamodb = { version = "1.3.0", features = ["test-util"] } +toasty-dynamodb = { path = "../../src/db/ddb", optional = true } +aws-config = { version = "1", optional = true } +aws-sdk-dynamodb = { version = "1.3.0", features = ["test-util"], optional = true } # Utilities std-util = { path = "../../src/std-util" } diff --git a/tests/client/src/db.rs b/tests/client/src/db.rs index 9a505d6..7f2e595 100644 --- a/tests/client/src/db.rs +++ b/tests/client/src/db.rs @@ -1,58 +1,7 @@ -use super::*; - -pub struct SetupDynamoDb; - -#[async_trait::async_trait] -impl Setup for SetupDynamoDb { - async fn setup(&self, schema: Schema) -> Db { - use aws_config::BehaviorVersion; - use aws_sdk_dynamodb::{config::Credentials, Client}; - use std::sync::atomic::{AtomicUsize, Ordering::Relaxed}; - - static CNT: AtomicUsize = AtomicUsize::new(0); - - let prefix = format!("test_{}_", CNT.fetch_add(1, Relaxed)); - - let mut sdk_config = aws_config::defaults(BehaviorVersion::latest()) - .credentials_provider(Credentials::for_tests()); - - if std::env::var("AWS_DEFAULT_REGION").is_err() { - sdk_config = sdk_config.region("local"); - } +#[cfg(feature = "dynamodb")] +pub mod dynamodb; - if std::env::var("AWS_ENDPOINT_URL_DYNAMODB").is_err() { - sdk_config = sdk_config.endpoint_url("http://localhost:8000"); - } +#[cfg(feature = "sqlite")] +pub mod sqlite; - let client = Client::new(&sdk_config.load().await); - - let driver = toasty_dynamodb::DynamoDB::new(client, Some(prefix)); - let db = toasty::Db::new(schema, driver).await; - db.reset_db().await.unwrap(); - db - } - - fn capability(&self) -> &Capability { - use toasty_core::driver::capability::KeyValue; - - &Capability::KeyValue(KeyValue { - primary_key_ne_predicate: false, - }) - } -} - -pub struct SetupSqlite; - -#[async_trait::async_trait] -impl Setup for SetupSqlite { - async fn setup(&self, schema: Schema) -> Db { - let driver = toasty_sqlite::Sqlite::in_memory(); - let db = toasty::Db::new(schema, driver).await; - db.reset_db().await.unwrap(); - db - } - - fn capability(&self) -> &Capability { - &Capability::Sql - } -} +use super::*; diff --git a/tests/client/src/db/dynamodb.rs b/tests/client/src/db/dynamodb.rs new file mode 100644 index 0000000..8bac0eb --- /dev/null +++ b/tests/client/src/db/dynamodb.rs @@ -0,0 +1,42 @@ +use super::*; + +pub struct SetupDynamoDb; + +#[async_trait::async_trait] +impl Setup for SetupDynamoDb { + async fn setup(&self, schema: Schema) -> Db { + use aws_config::BehaviorVersion; + use aws_sdk_dynamodb::{config::Credentials, Client}; + use std::sync::atomic::{AtomicUsize, Ordering::Relaxed}; + + static CNT: AtomicUsize = AtomicUsize::new(0); + + let prefix = format!("test_{}_", CNT.fetch_add(1, Relaxed)); + + let mut sdk_config = aws_config::defaults(BehaviorVersion::latest()) + .credentials_provider(Credentials::for_tests()); + + if std::env::var("AWS_DEFAULT_REGION").is_err() { + sdk_config = sdk_config.region("local"); + } + + if std::env::var("AWS_ENDPOINT_URL_DYNAMODB").is_err() { + sdk_config = sdk_config.endpoint_url("http://localhost:8000"); + } + + let client = Client::new(&sdk_config.load().await); + + let driver = toasty_dynamodb::DynamoDB::new(client, Some(prefix)); + let db = toasty::Db::new(schema, driver).await; + db.reset_db().await.unwrap(); + db + } + + fn capability(&self) -> &Capability { + use toasty_core::driver::capability::KeyValue; + + &Capability::KeyValue(KeyValue { + primary_key_ne_predicate: false, + }) + } +} diff --git a/tests/client/src/db/sqlite.rs b/tests/client/src/db/sqlite.rs new file mode 100644 index 0000000..da27b31 --- /dev/null +++ b/tests/client/src/db/sqlite.rs @@ -0,0 +1,17 @@ +use super::*; + +pub struct SetupSqlite; + +#[async_trait::async_trait] +impl Setup for SetupSqlite { + async fn setup(&self, schema: Schema) -> Db { + let driver = toasty_sqlite::Sqlite::in_memory(); + let db = toasty::Db::new(schema, driver).await; + db.reset_db().await.unwrap(); + db + } + + fn capability(&self) -> &Capability { + &Capability::Sql + } +} diff --git a/tests/client/src/lib.rs b/tests/client/src/lib.rs index dd6e08e..a222d03 100644 --- a/tests/client/src/lib.rs +++ b/tests/client/src/lib.rs @@ -30,22 +30,24 @@ macro_rules! tests { $f:ident ),+ ) => { + #[cfg(feature = "dynamodb")] mod dynamodb { $( #[tokio::test] $( #[$attrs] )* async fn $f() { - super::$f($crate::db::SetupDynamoDb).await; + super::$f($crate::db::dynamodb::SetupDynamoDb).await; } )* } + #[cfg(feature = "sqlite")] mod sqlite { $( #[tokio::test] $( #[$attrs] )* async fn $f() { - super::$f($crate::db::SetupSqlite).await; + super::$f($crate::db::sqlite::SetupSqlite).await; } )* }