-
Notifications
You must be signed in to change notification settings - Fork 355
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
add kill test #2996
base: main
Are you sure you want to change the base?
add kill test #2996
Changes from 6 commits
cbbbf7b
00d3c5e
72ad34d
6d9ecd5
01761ff
c2ed117
c736a23
9035e80
71e82b2
c623e21
5dc2dbf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
use anyhow::anyhow; | ||
use test_framework::{Test, TestGroup, TestResult}; | ||
|
||
use crate::tests::lifecycle::ContainerLifecycle; | ||
|
||
fn kill_with_empty_id_test() -> TestResult { | ||
let mut container = ContainerLifecycle::new(); | ||
|
||
// kill with empty id | ||
container.set_id(""); | ||
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"); | ||
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")), | ||
} | ||
Check warning on line 40 in tests/contest/contest/src/tests/kill/kill_test.rs GitHub Actions / check (x86_64, gnu)
Check warning on line 40 in tests/contest/contest/src/tests/kill/kill_test.rs GitHub Actions / check (x86_64, musl)
Check warning on line 40 in tests/contest/contest/src/tests/kill/kill_test.rs GitHub Actions / check (aarch64, gnu)
|
||
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")), | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think in both these cases you can use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. container.kill() return TestResult. type. |
||
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")), | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think here you need to call |
||
match container.kill() { | ||
TestResult::Failed(_) => TestResult::Passed, | ||
TestResult::Passed => TestResult::Failed(anyhow!("Expected failure but got success")), | ||
_ => TestResult::Failed(anyhow!("Unexpected test result")), | ||
Check warning on line 67 in tests/contest/contest/src/tests/kill/kill_test.rs GitHub Actions / check (x86_64, gnu)
Check warning on line 67 in tests/contest/contest/src/tests/kill/kill_test.rs GitHub Actions / check (x86_64, musl)
Check warning on line 67 in tests/contest/contest/src/tests/kill/kill_test.rs GitHub Actions / check (aarch64, gnu)
|
||
} | ||
} | ||
|
||
|
||
fn kill_start_container_test() -> TestResult { | ||
let container = ContainerLifecycle::new(); | ||
|
||
Check warning on line 74 in tests/contest/contest/src/tests/kill/kill_test.rs GitHub Actions / check (x86_64, gnu)
Check warning on line 74 in tests/contest/contest/src/tests/kill/kill_test.rs GitHub Actions / check (x86_64, musl)
Check warning on line 74 in tests/contest/contest/src/tests/kill/kill_test.rs GitHub Actions / check (aarch64, gnu)
|
||
// 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!(), | ||
} | ||
Check warning on line 87 in tests/contest/contest/src/tests/kill/kill_test.rs GitHub Actions / check (x86_64, gnu)
Check warning on line 87 in tests/contest/contest/src/tests/kill/kill_test.rs GitHub Actions / check (x86_64, musl)
Check warning on line 87 in tests/contest/contest/src/tests/kill/kill_test.rs GitHub Actions / check (aarch64, gnu)
|
||
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 | ||
Check warning on line 96 in tests/contest/contest/src/tests/kill/kill_test.rs GitHub Actions / check (x86_64, gnu)
Check warning on line 96 in tests/contest/contest/src/tests/kill/kill_test.rs GitHub Actions / check (x86_64, musl)
Check warning on line 96 in tests/contest/contest/src/tests/kill/kill_test.rs GitHub Actions / check (aarch64, gnu)
|
||
} | ||
|
||
|
||
pub fn get_kill_test() -> TestGroup { | ||
let mut test_group = TestGroup::new("kill_container"); | ||
|
||
let kill_with_empty_id_test = Test::new( | ||
Check warning on line 103 in tests/contest/contest/src/tests/kill/kill_test.rs GitHub Actions / check (x86_64, gnu)
Check warning on line 103 in tests/contest/contest/src/tests/kill/kill_test.rs GitHub Actions / check (x86_64, musl)
Check warning on line 103 in tests/contest/contest/src/tests/kill/kill_test.rs GitHub Actions / check (aarch64, gnu)
|
||
"kill_with_empty_id_test", | ||
Box::new(kill_with_empty_id_test), | ||
); | ||
let kill_non_existed_container = Test::new( | ||
"kill_non_existed_container", | ||
Box::new(kill_non_existed_container) | ||
); | ||
let kill_created_container_test = Test::new( | ||
"kill_created_container_test", | ||
Box::new(kill_created_container_test) | ||
Check warning on line 113 in tests/contest/contest/src/tests/kill/kill_test.rs GitHub Actions / check (x86_64, gnu)
Check warning on line 113 in tests/contest/contest/src/tests/kill/kill_test.rs GitHub Actions / check (x86_64, musl)
Check warning on line 113 in tests/contest/contest/src/tests/kill/kill_test.rs GitHub Actions / check (aarch64, gnu)
|
||
); | ||
let kill_stopped_container_test = Test::new( | ||
"kill_stopped_container_test", | ||
Box::new(kill_stopped_container_test) | ||
Check warning on line 117 in tests/contest/contest/src/tests/kill/kill_test.rs GitHub Actions / check (x86_64, gnu)
Check warning on line 117 in tests/contest/contest/src/tests/kill/kill_test.rs GitHub Actions / check (x86_64, musl)
Check warning on line 117 in tests/contest/contest/src/tests/kill/kill_test.rs GitHub Actions / check (aarch64, gnu)
|
||
); | ||
let kill_start_container_test = Test::new( | ||
"kill_start_container_test", | ||
Box::new(kill_start_container_test) | ||
Check warning on line 121 in tests/contest/contest/src/tests/kill/kill_test.rs GitHub Actions / check (x86_64, gnu)
Check warning on line 121 in tests/contest/contest/src/tests/kill/kill_test.rs GitHub Actions / check (x86_64, musl)
Check warning on line 121 in tests/contest/contest/src/tests/kill/kill_test.rs GitHub Actions / check (aarch64, gnu)
|
||
); | ||
test_group.add(vec![ | ||
Box::new(kill_with_empty_id_test), | ||
Box::new(kill_non_existed_container), | ||
Check warning on line 125 in tests/contest/contest/src/tests/kill/kill_test.rs GitHub Actions / check (x86_64, gnu)
Check warning on line 125 in tests/contest/contest/src/tests/kill/kill_test.rs GitHub Actions / check (x86_64, musl)
Check warning on line 125 in tests/contest/contest/src/tests/kill/kill_test.rs GitHub Actions / check (aarch64, gnu)
|
||
Box::new(kill_created_container_test), | ||
Box::new(kill_stopped_container_test), | ||
Box::new(kill_start_container_test) | ||
]); | ||
test_group | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod kill_test; | ||
|
||
pub use kill_test::get_kill_test; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly update the failed messages in others as well.