Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ready for integration test for the exec command. #622

Merged
merged 2 commits into from
Jan 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::thread::sleep;
use std::time::Duration;
use test_framework::{TestResult, TestableGroup};

use super::{create, delete, kill, start, state};
use super::{create, delete, exec, kill, start, state};

// By experimenting, somewhere around 50 is enough for youki process
// to get the kill signal and shut down
Expand Down Expand Up @@ -35,6 +35,11 @@ impl ContainerLifecycle {
create::create(&self.project_path, &self.container_id)
}

#[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)
}

pub fn start(&self) -> TestResult {
start::start(&self.project_path, &self.container_id)
}
Expand All @@ -60,15 +65,18 @@ impl<'a> TestableGroup<'a> for ContainerLifecycle {
fn get_name(&self) -> &'a str {
"lifecycle"
}

fn run_all(&self) -> Vec<(&'a str, TestResult)> {
vec![
("create", self.create()),
("start", self.start()),
// ("exec", self.exec(vec!["echo", "Hello"], Some("Hello\n"))),
("kill", self.kill()),
("state", self.state()),
("delete", self.delete()),
]
}

fn run_selected(&self, selected: &[&str]) -> Vec<(&'a str, TestResult)> {
let mut ret = Vec::new();
for name in selected {
Expand Down
29 changes: 29 additions & 0 deletions crates/integration_test/src/tests/lifecycle/exec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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};

pub fn exec(
project_path: &Path,
id: &str,
exec_cmd: Vec<&str>,
expected_output: Option<&str>,
) -> TestResult {
let res = Command::new(get_runtime_path())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.arg("--root")
.arg(project_path.join("runtime"))
.arg("exec")
.arg(id)
.args(exec_cmd)
.spawn()
.expect("failed to execute exec command")
.wait_with_output();
if let Some(expect) = expected_output {
let act = String::from_utf8(res.as_ref().unwrap().stdout.clone()).unwrap();
assert_result_eq!(expect, act.as_str(), "unexpected stdout.").unwrap();
}
get_result_from_output(res)
YJDoc2 marked this conversation as resolved.
Show resolved Hide resolved
}
1 change: 1 addition & 0 deletions crates/integration_test/src/tests/lifecycle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod container_create;
mod container_lifecycle;
mod create;
mod delete;
mod exec;
mod kill;
mod start;
mod state;
Expand Down