Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
Signed-off-by: Akiyama <[email protected]>
  • Loading branch information
YamasouA committed Dec 7, 2024
1 parent fd494c1 commit 73de531
Showing 1 changed file with 37 additions and 19 deletions.
56 changes: 37 additions & 19 deletions tests/contest/contest/src/tests/kill/kill_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,55 @@ fn kill_with_empty_id_test() -> TestResult {

// kill with empty id
container.set_id("");
match container.kill() {
let result = match container.kill() {
TestResult::Failed(_) => TestResult::Passed,
TestResult::Passed => TestResult::Failed(anyhow!("Expected failure but got success")),
_ => TestResult::Failed(anyhow!("Unexpected test result")),
}
};
container.delete();
result
}

fn kill_non_existed_container() -> TestResult {
let mut container = ContainerLifecycle::new();

// kill for non existed container
container.set_id("non-existent-container-id");
match container.kill() {
let result = match container.kill() {
TestResult::Failed(_) => TestResult::Passed,
TestResult::Passed => TestResult::Failed(anyhow!("Expected failure but got success")),
_ => TestResult::Failed(anyhow!("Unexpected test result")),
}
};
container.delete();
result
}
fn kill_created_container_test() -> TestResult {
let container = ContainerLifecycle::new();

// kill created container
match container.create() {
TestResult::Passed => {}
_ => return TestResult::Failed(anyhow!("Failed to create container")),
}
match container.kill() {
let result = match container.kill() {
TestResult::Passed => TestResult::Passed,
TestResult::Failed(_) => {
TestResult::Failed(anyhow!("Expected success but got failure"))
}
_ => TestResult::Failed(anyhow!("Unexpected test result")),
}
};
container.delete();
result
}

fn kill_stopped_container_test() -> TestResult {
let container = ContainerLifecycle::new();

// kill stopped container
match container.create() {
TestResult::Passed => {}
_ => return TestResult::Failed(anyhow!("Failed to create container")),
}
match container.delete() {
TestResult::Passed => {}
_ => return TestResult::Failed(anyhow!("Failed to delete container")),
Expand All @@ -58,36 +71,35 @@ fn kill_stopped_container_test() -> TestResult {

fn kill_start_container_test() -> TestResult {
let container = ContainerLifecycle::new();

// kill start container
match container.create() {
TestResult::Passed => {}
_ => return TestResult::Failed(anyhow!("Failed to recreate container")),
}

match container.start() {
TestResult::Passed => {}
TestResult::Failed(err) => {
return TestResult::Failed(anyhow!("Failed to start container: {:?}", err));
}
_ => unreachable!(),
TestResult::Passed => {}
TestResult::Failed(err) => {
return TestResult::Failed(anyhow!("Failed to start container: {:?}", err));
}
_ => unreachable!(),
}
match container.kill() {
let result = match container.kill() {
TestResult::Passed => TestResult::Passed,
TestResult::Failed(_) => {
TestResult::Failed(anyhow!("Expected success but got failure"))
}
_ => TestResult::Failed(anyhow!("Unexpected test result")),
}

// match container.delete() {
// TestResult::Passed => {}
// _ => return TestResult::Failed(anyhow!("Failed to delete container")),
// }
};
container.delete();
result
}


pub fn get_kill_test() -> TestGroup {
let mut test_group = TestGroup::new("kill_container");

let kill_with_empty_id_test = Test::new(
"kill_with_empty_id_test",
Box::new(kill_with_empty_id_test),
Expand All @@ -108,6 +120,12 @@ pub fn get_kill_test() -> TestGroup {
"kill_start_container_test",
Box::new(kill_start_container_test)
);
test_group.add(vec![Box::new(kill_with_empty_id_test), Box::new(kill_non_existed_container), Box::new(kill_created_container_test), Box::new(kill_stopped_container_test), Box::new(kill_start_container_test)]);
test_group.add(vec![
Box::new(kill_with_empty_id_test),
Box::new(kill_non_existed_container),
Box::new(kill_created_container_test),
Box::new(kill_stopped_container_test),
Box::new(kill_start_container_test)
]);
test_group
}

0 comments on commit 73de531

Please sign in to comment.