Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ edition = "2021"

[dependencies]
async-trait = "0.1"
aws-config = "0.4"
aws-sdk-dynamodb = "0.4"
aws-sdk-eventbridge = "0.4"
aws-smithy-client = { version = "0.34", features = ["test-util"] }
aws-smithy-http = "0.34"
aws-types = "0.4"
aws-config = "0.6"
aws-sdk-dynamodb = "0.6"
aws-sdk-eventbridge = "0.6"
aws-smithy-client = { version = "0.36", features = ["test-util"] }
aws-smithy-http = "0.36"
aws-types = "0.6"
futures = { version = "0.3", features = ["std"] }
lambda_runtime = { version = "0.4", optional = true }
lambda_http = { version = "0.4", optional = true }
Expand Down
8 changes: 7 additions & 1 deletion src/event_bus/eventbridge/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ mod tests {
async fn get_mock_config() -> Config {
let cfg = aws_config::from_env()
.region(Region::new("eu-west-1"))
.credentials_provider(Credentials::from_keys("accesskey", "privatekey", None))
.credentials_provider(Credentials::new(
"accesskey",
"privatekey",
None,
None,
"dummy",
))
.load()
.await;

Expand Down
61 changes: 29 additions & 32 deletions src/store/dynamodb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,21 @@ use ext::AttributeValuesExt;
/// We have to pass a generic type parameter `C` for the underlying client,
/// restricted to something that implements the SmithyConnector trait so we can
/// use it with both the actual AWS SDK client and a mock implementation.
pub struct DynamoDBStore<C> {
client: Client<C>,
pub struct DynamoDBStore {
client: Client,
table_name: String,
}

impl<C> DynamoDBStore<C>
where
C: aws_smithy_client::bounds::SmithyConnector,
{
pub fn new(client: Client<C>, table_name: String) -> DynamoDBStore<C> {
impl DynamoDBStore {
pub fn new(client: Client, table_name: String) -> DynamoDBStore {
DynamoDBStore { client, table_name }
}
}

impl<C> Store for DynamoDBStore<C> where C: aws_smithy_client::bounds::SmithyConnector {}
impl Store for DynamoDBStore {}

#[async_trait]
impl<C> StoreGetAll for DynamoDBStore<C>
where
C: aws_smithy_client::bounds::SmithyConnector,
{
impl StoreGetAll for DynamoDBStore {
/// Get all items
#[instrument(skip(self))]
async fn all(&self, next: Option<&str>) -> Result<ProductRange, Error> {
Expand Down Expand Up @@ -65,10 +59,7 @@ where
}

#[async_trait]
impl<C> StoreGet for DynamoDBStore<C>
where
C: aws_smithy_client::bounds::SmithyConnector,
{
impl StoreGet for DynamoDBStore {
/// Get item
#[instrument(skip(self))]
async fn get(&self, id: &str) -> Result<Option<Product>, Error> {
Expand All @@ -89,10 +80,7 @@ where
}

#[async_trait]
impl<C> StorePut for DynamoDBStore<C>
where
C: aws_smithy_client::bounds::SmithyConnector,
{
impl StorePut for DynamoDBStore {
/// Create or update an item
#[instrument(skip(self))]
async fn put(&self, product: &Product) -> Result<(), Error> {
Expand All @@ -109,10 +97,7 @@ where
}

#[async_trait]
impl<C> StoreDelete for DynamoDBStore<C>
where
C: aws_smithy_client::bounds::SmithyConnector,
{
impl StoreDelete for DynamoDBStore {
/// Delete item
#[instrument(skip(self))]
async fn delete(&self, id: &str) -> Result<(), Error> {
Expand Down Expand Up @@ -168,14 +153,20 @@ mod tests {
use super::*;
use crate::Error;
use aws_sdk_dynamodb::{Client, Config, Credentials, Region};
use aws_smithy_client::test_connection::TestConnection;
use aws_smithy_client::{erase::DynConnector, test_connection::TestConnection};
use aws_smithy_http::body::SdkBody;

/// Config for mocking DynamoDB
async fn get_mock_config() -> Config {
let cfg = aws_config::from_env()
.region(Region::new("eu-west-1"))
.credentials_provider(Credentials::from_keys("accesskey", "privatekey", None))
.credentials_provider(Credentials::new(
"accesskey",
"privatekey",
None,
None,
"dummy",
))
.load()
.await;

Expand Down Expand Up @@ -203,7 +194,8 @@ mod tests {
.body(SdkBody::from(r#"{"Items": []}"#))
.unwrap(),
)]);
let client = Client::from_conf_conn(get_mock_config().await, conn.clone());
let client =
Client::from_conf_conn(get_mock_config().await, DynConnector::new(conn.clone()));
let store = DynamoDBStore::new(client, "test".to_string());

// WHEN getting all items
Expand All @@ -229,7 +221,8 @@ mod tests {
.body(SdkBody::from(r#"{"Items": [{"id": {"S": "1"}, "name": {"S": "test1"}, "price": {"N": "1.0"}}]}"#))
.unwrap(),
)]);
let client = Client::from_conf_conn(get_mock_config().await, conn.clone());
let client =
Client::from_conf_conn(get_mock_config().await, DynConnector::new(conn.clone()));
let store = DynamoDBStore::new(client, "test".to_string());

// WHEN getting all items
Expand Down Expand Up @@ -264,7 +257,8 @@ mod tests {
))
.unwrap(),
)]);
let client = Client::from_conf_conn(get_mock_config().await, conn.clone());
let client =
Client::from_conf_conn(get_mock_config().await, DynConnector::new(conn.clone()));
let store = DynamoDBStore::new(client, "test".to_string());

// WHEN getting all items
Expand Down Expand Up @@ -293,7 +287,8 @@ mod tests {
.body(SdkBody::from("{}"))
.unwrap(),
)]);
let client = Client::from_conf_conn(get_mock_config().await, conn.clone());
let client =
Client::from_conf_conn(get_mock_config().await, DynConnector::new(conn.clone()));
let store = DynamoDBStore::new(client, "test".to_string());

// WHEN deleting an item
Expand All @@ -318,7 +313,8 @@ mod tests {
.body(SdkBody::from(r#"{"Item": {"id": {"S": "1"}, "name": {"S": "test1"}, "price": {"N": "1.0"}}}"#))
.unwrap(),
)]);
let client = Client::from_conf_conn(get_mock_config().await, conn.clone());
let client =
Client::from_conf_conn(get_mock_config().await, DynConnector::new(conn.clone()));
let store = DynamoDBStore::new(client, "test".to_string());

// WHEN getting an item
Expand Down Expand Up @@ -351,7 +347,8 @@ mod tests {
.body(SdkBody::from(r#"{"Attributes": {"id": {"S": "1"}, "name": {"S": "test1"}, "price": {"N": "1.5"}}}"#))
.unwrap(),
)]);
let client = Client::from_conf_conn(get_mock_config().await, conn.clone());
let client =
Client::from_conf_conn(get_mock_config().await, DynConnector::new(conn.clone()));
let store = DynamoDBStore::new(client, "test".to_string());
let product = Product {
id: "1".to_string(),
Expand Down