-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding support for the Amazon DynamoDB local container
- Loading branch information
Jack Wright
committed
Dec 13, 2018
1 parent
ae52937
commit d8f6188
Showing
9 changed files
with
199 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "tc_dynamodb_local" | ||
version = "0.1.0" | ||
authors = [ "Jack Wright <[email protected]>" ] | ||
description = "Testcontainers image for local dynamodb" | ||
license = "MIT OR Apache-2.0" | ||
repository = "https://github.com/coblox/testcontainers-rs" | ||
categories = ["development-tools::testing"] | ||
keywords = ["docker", "testcontainers", "dynamodb"] | ||
|
||
[dependencies] | ||
tc_core = { path = "../../core", version = "0.2" } | ||
log = "0.4" |
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,11 @@ | ||
# DynamoDb Local | ||
|
||
This crate provides `DynamoDB` as an `Image` for `testcontainers`. | ||
|
||
By default the `latest` will be used for the dynamodb-local container. This can be overridden by creating the DynamoDB | ||
instance with `DynamoDB::with_tag_args`. | ||
|
||
The period of time waiting for the dynamodb-local image to be available can be adjusted from the default value of | ||
2000 milliseconds by setting the environment variable DYNAMODB_ADDITIONAL_SLEEP_PERIOD (in millis). | ||
|
||
Information on the DynamoDB local container can be found at: https://hub.docker.com/r/amazon/dynamodb-local/ |
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,85 @@ | ||
use std::{env::var, thread::sleep, time::Duration}; | ||
use tc_core::{Image, Container, Docker, WaitForMessage}; | ||
|
||
const ADDITIONAL_SLEEP_PERIOD: &'static str = "DYNAMODB_ADDITIONAL_SLEEP_PERIOD"; | ||
const DEFAULT_WAIT: u64 = 2000; | ||
const CONTAINER_IDENTIFIER: &'static str = "amazon/dynamodb-local"; | ||
const DEFAULT_TAG: &'static str = "latest"; | ||
|
||
|
||
#[derive(Debug, Default, Clone)] | ||
pub struct DynamoDbArgs; | ||
|
||
impl IntoIterator for DynamoDbArgs { | ||
type Item = String; | ||
type IntoIter = ::std::vec::IntoIter<String>; | ||
|
||
fn into_iter(self) -> <Self as IntoIterator>::IntoIter { | ||
vec![].into_iter() | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct DynamoDb { | ||
tag: String, | ||
arguments: DynamoDbArgs | ||
} | ||
|
||
impl Default for DynamoDb { | ||
fn default() -> Self { | ||
DynamoDb { | ||
tag: DEFAULT_TAG.to_string(), | ||
arguments: DynamoDbArgs {} | ||
} | ||
} | ||
} | ||
|
||
impl Image for DynamoDb { | ||
type Args = DynamoDbArgs; | ||
|
||
fn descriptor(&self) -> String { | ||
format!("{}:{}", CONTAINER_IDENTIFIER, &self.tag) | ||
} | ||
|
||
fn wait_until_ready<D: Docker>(&self, container: &Container<D, Self>) { | ||
container | ||
.logs() | ||
.stdout | ||
.wait_for_message("Initializing DynamoDB Local with the following configuration") | ||
.unwrap(); | ||
|
||
let additional_sleep_period = var(ADDITIONAL_SLEEP_PERIOD) | ||
.map(|value| value.parse().unwrap_or(DEFAULT_WAIT)) | ||
.unwrap_or(DEFAULT_WAIT); | ||
|
||
let sleep_period = Duration::from_millis(additional_sleep_period); | ||
|
||
trace!( | ||
"Waiting for an additional {:?} for container {}.", | ||
sleep_period, | ||
container.id() | ||
); | ||
|
||
sleep(sleep_period) | ||
} | ||
|
||
fn args(&self) -> <Self as Image>::Args { | ||
self.arguments.clone() | ||
} | ||
|
||
fn with_args(self, arguments: <Self as Image>::Args) -> Self { | ||
DynamoDb { | ||
arguments, ..self | ||
} | ||
} | ||
|
||
} | ||
|
||
impl DynamoDb { | ||
pub fn with_tag_args(self, tag_str: &str, arguments: <Self as Image>::Args) -> Self { | ||
DynamoDb{tag: tag_str.to_string(), arguments, ..self} | ||
} | ||
} | ||
|
||
|
||
|
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,8 @@ | ||
#![deny(missing_debug_implementations)] | ||
|
||
#[macro_use] | ||
extern crate log; | ||
extern crate tc_core; | ||
|
||
mod image; | ||
pub use image::*; |
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