k8s_test_framework/
util.rs

1use log::info;
2
3use crate::Result;
4
5pub async fn run_command(mut command: tokio::process::Command) -> Result<()> {
6    info!("Running command `{command:?}`");
7    let exit_status = command.spawn()?.wait().await?;
8    if !exit_status.success() {
9        return Err(format!("exec failed: {command:?}").into());
10    }
11    Ok(())
12}
13
14pub fn run_command_blocking(mut command: std::process::Command) -> Result<()> {
15    info!("Running command blocking `{command:?}`");
16    let exit_status = command.spawn()?.wait()?;
17    if !exit_status.success() {
18        return Err(format!("exec failed: {command:?}").into());
19    }
20    Ok(())
21}
22
23pub async fn run_command_output(mut command: tokio::process::Command) -> Result<String> {
24    info!("Fetching command `{command:?}`");
25    let output = command.spawn()?.wait_with_output().await?;
26    if !output.status.success() {
27        return Err(format!("exec failed: {command:?}").into());
28    }
29
30    let output = String::from_utf8(output.stdout)?;
31    Ok(output)
32}