extern crate pretty_env_logger; extern crate spectral; extern crate tc_cli_client; extern crate tc_core; use spectral::prelude::*; use std::collections::HashMap; use std::time::Duration; use std::time::Instant; use tc_cli_client::Cli; use tc_core::Container; use tc_core::Docker; use tc_core::Image; use tc_core::WaitForMessage; #[derive(Default)] struct HelloWorld; impl Image for HelloWorld { type Args = Vec; type EnvVars = HashMap; fn descriptor(&self) -> String { String::from("hello-world") } fn wait_until_ready(&self, container: &Container) { container .logs() .stdout .wait_for_message("Hello from Docker!") .unwrap(); } fn args(&self) -> ::Args { vec![] } fn env_vars(&self) -> Self::EnvVars { HashMap::new() } fn with_args(self, _arguments: ::Args) -> Self { self } } #[test] fn should_wait_for_at_least_one_second_before_fetching_logs() { let _ = pretty_env_logger::try_init(); let docker = Cli::default(); let before_run = Instant::now(); let container = docker.run(HelloWorld); let after_run = Instant::now(); let before_logs = Instant::now(); docker.logs(container.id()); let after_logs = Instant::now(); assert_that(&(after_run - before_run)).is_greater_than(Duration::from_secs(1)); assert_that(&(after_logs - before_logs)).is_less_than(Duration::from_secs(1)); }