diff --git a/Cargo.lock b/Cargo.lock index 8a4998b3..d3ece6bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1293,6 +1293,10 @@ checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" [[package]] name = "runtimetest" version = "0.0.1" +dependencies = [ + "nix", + "oci-spec 0.5.2 (git+https://github.com/containers/oci-spec-rs?rev=54c5e386f01ab37c9305cc4a83404eb157e42440)", +] [[package]] name = "rustc_version" diff --git a/crates/integration_test/src/tests/readonly_paths/readonly_paths_tests.rs b/crates/integration_test/src/tests/readonly_paths/readonly_paths_tests.rs index 32fde6d9..a22cbbc3 100644 --- a/crates/integration_test/src/tests/readonly_paths/readonly_paths_tests.rs +++ b/crates/integration_test/src/tests/readonly_paths/readonly_paths_tests.rs @@ -56,9 +56,8 @@ fn check_readonly_paths() -> TestResult { ]; let spec = get_spec(ro_paths); - test_inside_container(spec, &|bundle| { + test_inside_container(spec, &|bundle_path| { use std::{fs, io}; - let bundle_path = bundle.as_ref(); let test_dir = bundle_path.join(&ro_dir_sub); match fs::create_dir_all(&test_dir) { @@ -108,9 +107,8 @@ fn check_readonly_rel_path() -> TestResult { let ro_paths = vec![ro_rel_path.to_string()]; let spec = get_spec(ro_paths); - test_inside_container(spec, &|bundle| { + test_inside_container(spec, &|bundle_path| { use std::{fs, io}; - let bundle_path = bundle.as_ref(); let test_file = bundle_path.join(ro_rel_path); match fs::metadata(&test_file) { @@ -140,9 +138,8 @@ fn check_readonly_symlinks() -> TestResult { let spec = get_spec(ro_paths); - test_inside_container(spec, &|bundle| { + test_inside_container(spec, &|bundle_path| { use std::{fs, io}; - let bundle_path = bundle.as_ref(); let test_file = bundle_path.join(ro_symlink); match std::os::unix::fs::symlink("../readonly_symlink", &test_file) { @@ -185,11 +182,9 @@ fn test_node(mode: u32) -> TestResult { let spec = get_spec(ro_paths); - test_inside_container(spec, &|bundle| { + test_inside_container(spec, &|bundle_path| { use std::os::unix::fs::OpenOptionsExt; use std::{fs, io}; - - let bundle_path = bundle.as_ref(); let test_file = bundle_path.join(&ro_device); let mut opts = fs::OpenOptions::new(); diff --git a/crates/integration_test/src/utils/test_utils.rs b/crates/integration_test/src/utils/test_utils.rs index 4accf9fb..d5a9bf12 100644 --- a/crates/integration_test/src/utils/test_utils.rs +++ b/crates/integration_test/src/utils/test_utils.rs @@ -1,7 +1,7 @@ use super::{generate_uuid, prepare_bundle, set_config}; ///! Contains utility functions for testing ///! Similar to https://github.com/opencontainers/runtime-tools/blob/master/validation/util/test.go -use super::{get_runtime_path, get_runtimetest_path, TempDir}; +use super::{get_runtime_path, get_runtimetest_path}; use anyhow::{anyhow, bail, Context, Result}; use oci_spec::runtime::Spec; use serde::{Deserialize, Serialize}; @@ -146,13 +146,16 @@ pub fn test_outside_container( // mostly needs a name that better expresses what this actually does pub fn test_inside_container( spec: Spec, - setup_for_test: &dyn Fn(&TempDir) -> Result<()>, + setup_for_test: &dyn Fn(&Path) -> Result<()>, ) -> TestResult { let id = generate_uuid(); let bundle = prepare_bundle(&id).unwrap(); // This will do the required setup for the test - test_result!(setup_for_test(&bundle)); + test_result!(setup_for_test( + &bundle.as_ref().join("bundle").join("rootfs") + )); + // std::thread::sleep_ms(50000); set_config(&bundle, &spec).unwrap(); // as we have to run runtimetest inside the container, and is expects diff --git a/crates/runtimetest/Cargo.toml b/crates/runtimetest/Cargo.toml index ea84166c..3d8fc4d3 100644 --- a/crates/runtimetest/Cargo.toml +++ b/crates/runtimetest/Cargo.toml @@ -6,3 +6,5 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +oci-spec = { git = "https://github.com/containers/oci-spec-rs", rev = "54c5e386f01ab37c9305cc4a83404eb157e42440" } +nix = "0.23.1" \ No newline at end of file diff --git a/crates/runtimetest/README.md b/crates/runtimetest/README.md index ac010dec..05752ddb 100644 --- a/crates/runtimetest/README.md +++ b/crates/runtimetest/README.md @@ -1,6 +1,6 @@ # Runtime test -This is the binary which runs the tests inside the container process, and checks that constraints and restrictions are upheld from inside the container. +This is the binary which runs the tests inside the container process, and checks that constraints and restrictions are upheld from inside the container. This is supposed to be rust version of [runtimetest command](https://github.com/opencontainers/runtime-tools/tree/master/cmd/runtimetest) from runtime tools. This is primarily used from the `test_inside_container` function related tests in the integration tests. diff --git a/crates/runtimetest/src/main.rs b/crates/runtimetest/src/main.rs index 2103ca8a..0304bdc8 100644 --- a/crates/runtimetest/src/main.rs +++ b/crates/runtimetest/src/main.rs @@ -1,3 +1,23 @@ -fn main() { - println!("This is where the internal tests will go later..."); +mod tests; +mod utils; + +use oci_spec::runtime::Spec; +use std::path::PathBuf; + +const SPEC_PATH: &'static str = "/config.json"; + +fn get_spec() -> Spec { + let path = PathBuf::from(SPEC_PATH); + match Spec::load(path) { + Ok(spec) => spec, + Err(e) => { + eprintln!("Error in loading spec, {:?}", e); + std::process::exit(66); + } + } +} + +fn main() { + let spec = get_spec(); + tests::validate_readonly_paths(&spec); }