diff --git a/src/docker.rs b/src/docker.rs index 40cd134..2b8da69 100644 --- a/src/docker.rs +++ b/src/docker.rs @@ -32,6 +32,15 @@ impl Docker { child.wait().unwrap(); } + pub fn get_exit_status(name: &str) -> isize { + let output = Command::new("docker") + .args(["inspect", name, "--format={{.State.ExitCode}}"]) + .output() + .expect("unable to exit status"); + let out = String::from_utf8(output.stdout).unwrap(); + let out = out.trim(); + out.parse::().unwrap() + } pub fn get_logs(name: &str) -> String { let output = Command::new("docker") .args(["logs", name]) @@ -60,7 +69,7 @@ mod tests { use super::*; #[test] - fn test_docker() { + fn test_docker_util() { Docker::version(); let name = format!("test_sleep__{}", get_random(4)); let mut env = HashMap::new(); @@ -79,6 +88,7 @@ mod tests { assert!(logs.contains("running")); assert!(logs.contains("FOO=BAR")); assert!(logs.contains("BAZ=BOO")); + assert_eq!(Docker::get_exit_status(&name), 0); Docker::rm_container(&name, true); } }