-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add per-db feature flags to tests (#28)
- Loading branch information
1 parent
a95aa51
commit 096c64d
Showing
6 changed files
with
83 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters