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

Add create integration tests. #583

Closed
wants to merge 2 commits into from
Closed
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
3 changes: 3 additions & 0 deletions crates/integration_test/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod tests;
mod utils;

use crate::tests::create::get_create_test_group;
use crate::tests::lifecycle::{ContainerCreate, ContainerLifecycle};
use crate::tests::linux_ns_itype::get_ns_itype_tests;
use crate::tests::pidfile::get_pidfile_test;
Expand Down Expand Up @@ -79,6 +80,7 @@ fn main() -> Result<()> {
let cgroup_v1_network = cgroups::network::get_test_group();
let cgroup_v1_blkio = cgroups::blkio::get_test_group();
let seccomp_notify = get_seccomp_notify_test();
let create = get_create_test_group();

tm.add_test_group(&cl);
tm.add_test_group(&cc);
Expand All @@ -92,6 +94,7 @@ fn main() -> Result<()> {
tm.add_test_group(&cgroup_v1_network);
tm.add_test_group(&cgroup_v1_blkio);
tm.add_test_group(&seccomp_notify);
tm.add_test_group(&create);

tm.add_cleanup(Box::new(cgroups::cleanup_v1));
tm.add_cleanup(Box::new(cgroups::cleanup_v2));
Expand Down
51 changes: 51 additions & 0 deletions crates/integration_test/src/tests/create.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use test_framework::{Test, TestGroup, TestResult};

// runtime should not create container with empty id
fn create_empty_id() -> TestResult {
// let temp = create::create(&self.project_path, "");
// match temp {
// TestResult::Passed => TestResult::Failed(anyhow::anyhow!(
// "Container should not have been created with empty id, but was created."
// )),
// TestResult::Failed(_) => TestResult::Passed,
// TestResult::Skipped => TestResult::Skipped,
// }
todo!()
}

// runtime should create container with valid id
fn create_valid_id(&self) -> TestResult {
let temp = create::create(&self.project_path, &self.container_id);
if let TestResult::Passed = temp {
kill::kill(&self.project_path, &self.container_id);
delete::delete(&self.project_path, &self.container_id);
}
temp
}

// runtime should not create container with is that already exists
fn create_duplicate_id(&self) -> TestResult {
let id = generate_uuid().to_string();
let _ = create::create(&self.project_path, &id);
let temp = create::create(&self.project_path, &id);
kill::kill(&self.project_path, &id);
delete::delete(&self.project_path, &id);
match temp {
TestResult::Passed => TestResult::Failed(anyhow::anyhow!(
"Container should not have been created with same id, but was created."
)),
TestResult::Failed(_) => TestResult::Passed,
TestResult::Skipped => TestResult::Skipped,
}
}

pub fn get_create_test_group<'a>() -> TestGroup<'a> {
let empty_id = Box::new(Test::new("empty_id", Box::new(create_empty_id)));
let valid_id = Box::new(Test::new("valid_id", Box::new(create_valid_id)));
let duplicate_id = Box::new(Test::new("duplicate_id", Box::new(create_duplicate_id)));

let mut tg = TestGroup::new("create");
tg.add(vec![empty_id, valid_id, duplicate_id]);

tg
}
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 @@ -6,6 +6,7 @@ mod kill;
mod start;
mod state;
mod util;

pub use container_create::ContainerCreate;
pub use container_lifecycle::ContainerLifecycle;
pub use util::get_result_from_output;
1 change: 1 addition & 0 deletions crates/integration_test/src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod cgroups;
pub mod create;
pub mod lifecycle;
pub mod linux_ns_itype;
pub mod pidfile;
Expand Down