1
0
Fork 0
mirror of https://github.com/containers/youki synced 2024-06-09 00:06:18 +02:00

fixed more command

Signed-off-by: yihuaf <yihuaf@unkies.org>
This commit is contained in:
yihuaf 2023-05-01 20:33:10 +00:00
parent c57df38bb9
commit c780e68185
7 changed files with 25 additions and 25 deletions

View File

@ -131,9 +131,10 @@ fn checkpoint(
.expect("failed to execute checkpoint command")
.wait_with_output();
let result = get_result_from_output(checkpoint);
if let TestResult::Failed(_) = result {
return result;
if let Err(e) = get_result_from_output(checkpoint) {
return TestResult::Failed(anyhow::anyhow!(
"failed to execute checkpoint command: {e}"
));
}
// Check for complete checkpoint

View File

@ -32,19 +32,16 @@ impl ContainerLifecycle {
}
pub fn create(&self) -> TestResult {
match create::create(&self.project_path, &self.container_id) {
Ok(_) => TestResult::Passed,
Err(err) => TestResult::Failed(err),
}
create::create(&self.project_path, &self.container_id).into()
}
#[allow(dead_code)]
pub fn exec(&self, cmd: Vec<&str>, expected_output: Option<&str>) -> TestResult {
exec::exec(&self.project_path, &self.container_id, cmd, expected_output)
exec::exec(&self.project_path, &self.container_id, cmd, expected_output).into()
}
pub fn start(&self) -> TestResult {
start::start(&self.project_path, &self.container_id)
start::start(&self.project_path, &self.container_id).into()
}
pub fn state(&self) -> TestResult {
@ -56,11 +53,11 @@ impl ContainerLifecycle {
// sleep a little, so the youki process actually gets the signal and shuts down
// otherwise, the tester moves on to next tests before the youki has gotten signal, and delete test can fail
sleep(SLEEP_TIME);
ret
ret.into()
}
pub fn delete(&self) -> TestResult {
delete::delete(&self.project_path, &self.container_id)
delete::delete(&self.project_path, &self.container_id).into()
}
pub fn checkpoint_leave_running(&self) -> TestResult {

View File

@ -1,9 +1,9 @@
use super::get_result_from_output;
use crate::utils::delete_container;
use std::path::Path;
use test_framework::TestResult;
use anyhow::{bail, Result};
pub fn delete(project_path: &Path, id: &str) -> TestResult {
pub fn delete(project_path: &Path, id: &str) -> Result<()>{
let res = delete_container(id, project_path)
.expect("failed to execute delete command")
.wait_with_output();

View File

@ -2,14 +2,15 @@ use super::get_result_from_output;
use crate::utils::get_runtime_path;
use std::path::Path;
use std::process::{Command, Stdio};
use test_framework::{assert_result_eq, TestResult};
use anyhow::Result;
use test_framework::{assert_result_eq};
pub fn exec(
project_path: &Path,
id: &str,
exec_cmd: Vec<&str>,
expected_output: Option<&str>,
) -> TestResult {
) -> Result<()>{
let res = Command::new(get_runtime_path())
.stdout(Stdio::piped())
.stderr(Stdio::piped())

View File

@ -1,9 +1,10 @@
use anyhow::Result;
use super::get_result_from_output;
use crate::utils::kill_container;
use std::path::Path;
use test_framework::TestResult;
pub fn kill(project_path: &Path, id: &str) -> TestResult {
pub fn kill(project_path: &Path, id: &str) -> Result<()>{
let res = kill_container(id, project_path)
.expect("failed to execute kill command")
.wait_with_output();

View File

@ -1,9 +1,9 @@
use super::get_result_from_output;
use crate::utils::test_utils::start_container;
use std::path::Path;
use test_framework::TestResult;
use anyhow::Result;
pub fn start(project_path: &Path, id: &str) -> TestResult {
pub fn start(project_path: &Path, id: &str) -> Result<()> {
let res = start_container(id, project_path)
.expect("failed to execute start command")
.wait_with_output();

View File

@ -1,21 +1,21 @@
use std::{io, process};
use test_framework::TestResult;
use anyhow::{Result, bail};
pub fn get_result_from_output(res: io::Result<process::Output>) -> TestResult {
pub fn get_result_from_output(res: io::Result<process::Output>) -> Result<()>{
match res {
io::Result::Ok(output) => {
let stderr = String::from_utf8(output.stderr).unwrap();
if stderr.contains("Error") || stderr.contains("error") {
let stdout = String::from_utf8(output.stdout).unwrap();
TestResult::Failed(anyhow::anyhow!(
bail!(
"Error :\nstdout : {}\nstderr : {}",
stdout,
stderr
))
)
} else {
TestResult::Passed
Ok(())
}
}
io::Result::Err(e) => TestResult::Failed(anyhow::Error::new(e)),
io::Result::Err(e) => Err(anyhow::Error::new(e)),
}
}