feat: get exit status

This commit is contained in:
Aravinth Manivannan 2023-09-27 00:34:32 +05:30
parent 17510c4ac2
commit b3f7cb943e
Signed by: realaravinth
GPG key ID: F8F50389936984FF

View file

@ -32,6 +32,15 @@ impl Docker {
child.wait().unwrap(); 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::<isize>().unwrap()
}
pub fn get_logs(name: &str) -> String { pub fn get_logs(name: &str) -> String {
let output = Command::new("docker") let output = Command::new("docker")
.args(["logs", name]) .args(["logs", name])
@ -60,7 +69,7 @@ mod tests {
use super::*; use super::*;
#[test] #[test]
fn test_docker() { fn test_docker_util() {
Docker::version(); Docker::version();
let name = format!("test_sleep__{}", get_random(4)); let name = format!("test_sleep__{}", get_random(4));
let mut env = HashMap::new(); let mut env = HashMap::new();
@ -79,6 +88,7 @@ mod tests {
assert!(logs.contains("running")); assert!(logs.contains("running"));
assert!(logs.contains("FOO=BAR")); assert!(logs.contains("FOO=BAR"));
assert!(logs.contains("BAZ=BOO")); assert!(logs.contains("BAZ=BOO"));
assert_eq!(Docker::get_exit_status(&name), 0);
Docker::rm_container(&name, true); Docker::rm_container(&name, true);
} }
} }