use std::{env::var, thread::sleep, time::Duration};
use tc_core::{Image, Container, Docker, WaitForMessage};
const DEFAULT_WAIT: u64 = 1000;
#[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 {
arguments: DynamoDbArgs
}
impl Default for DynamoDb {
fn default() -> Self {
DynamoDb {
arguments: DynamoDbArgs {}
}
}
}
impl Image for DynamoDb {
type Args = DynamoDbArgs;
fn descriptor(&self) -> String {
"amazon/dynamodb-local:1.11.119".to_string()
}
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("DYNAMODB_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
}
}
}