1
0
Fork 0
mirror of https://github.com/containers/youki synced 2024-05-10 09:36:13 +02:00
youki/tests/contest/contest/src/tests/lifecycle/create.rs
Toru Komatsu 464344923f
Name the test tools `contest` (#2486)
* Name the test tools `contest`

Signed-off-by: utam0k <k0ma@utam0k.jp>

* Address the feedbacks

Signed-off-by: utam0k <k0ma@utam0k.jp>

* Fix a build error

Signed-off-by: utam0k <k0ma@utam0k.jp>

* Fix a workflow

Signed-off-by: utam0k <k0ma@utam0k.jp>

* Address the feedbacks

Signed-off-by: utam0k <k0ma@utam0k.jp>

---------

Signed-off-by: utam0k <k0ma@utam0k.jp>
2024-01-12 14:28:47 +05:30

35 lines
1.1 KiB
Rust

use crate::utils::get_runtime_path;
use anyhow::{bail, Result};
use std::io;
use std::path::Path;
use std::process::{Command, Stdio};
// There are still some issues here in case we put stdout and stderr as piped
// the youki process created halts indefinitely which is why we pass null, and
// use wait instead of wait_with_output
pub fn create(project_path: &Path, id: &str) -> Result<()> {
let res = Command::new(get_runtime_path())
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null())
.arg("--root")
.arg(project_path.join("runtime"))
.arg("create")
.arg("--bundle")
.arg(project_path.join("bundle"))
.arg(id)
.spawn()
.expect("Cannot execute create command")
.wait();
match res {
io::Result::Ok(status) => {
if status.success() {
Ok(())
} else {
bail!("create exited with nonzero status : {}", status)
}
}
io::Result::Err(e) => bail!("create failed : {}", e),
}
}