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 = "redis"; const DEFAULT_TAG: &'static str = "5.0"; #[derive(Debug, Default, Clone)] pub struct RedisArgs; impl IntoIterator for RedisArgs { type Item = String; type IntoIter = ::std::vec::IntoIter<String>; fn into_iter(self) -> <Self as IntoIterator>::IntoIter { vec![].into_iter() } } #[derive(Debug)] pub struct Redis { tag: String, arguments: RedisArgs, } impl Default for Redis { fn default() -> Self { Redis { tag: DEFAULT_TAG.to_string(), arguments: RedisArgs {}, } } } impl Image for Redis { type Args = RedisArgs; 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("Ready to accept connections") .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 { Redis { arguments, ..self } } } impl Redis { pub fn with_tag(self, tag_str: &str) -> Self { Redis { tag: tag_str.to_string(), ..self } } }