1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use std::collections::HashMap;
use tc_core::{Container, Docker, Image, WaitForMessage};

const CONTAINER_IDENTIFIER: &'static str = "softwaremill/elasticmq";
const DEFAULT_TAG: &'static str = "0.14.6";

#[derive(Debug, Default, Clone)]
pub struct ElasticMQArgs;

impl IntoIterator for ElasticMQArgs {
    type Item = String;
    type IntoIter = ::std::vec::IntoIter<String>;

    fn into_iter(self) -> <Self as IntoIterator>::IntoIter {
        vec![].into_iter()
    }
}

#[derive(Debug)]
pub struct ElasticMQ {
    tag: String,
    arguments: ElasticMQArgs,
}

impl Default for ElasticMQ {
    fn default() -> Self {
        ElasticMQ {
            tag: DEFAULT_TAG.to_string(),
            arguments: ElasticMQArgs {},
        }
    }
}

impl Image for ElasticMQ {
    type Args = ElasticMQArgs;
    type EnvVars = HashMap<String, String>;

    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("Started SQS rest server")
            .unwrap();
    }

    fn args(&self) -> <Self as Image>::Args {
        self.arguments.clone()
    }

    fn env_vars(&self) -> Self::EnvVars {
        HashMap::new()
    }

    fn with_args(self, arguments: <Self as Image>::Args) -> Self {
        ElasticMQ { arguments, ..self }
    }
}

impl ElasticMQ {
    pub fn with_tag(self, tag_str: &str) -> Self {
        ElasticMQ {
            tag: tag_str.to_string(),
            ..self
        }
    }
}