Skip to content

Commit

Permalink
Refactor test dir structure (#2421)
Browse files Browse the repository at this point in the history
* Move individual rust-oci-tests components in the tests dir

We can use several things from test_framework and even integration_test
for additional tests such as podman rootless and wasm tests

Signed-off-by: Yashodhan Joshi <yjdoc2@gmail.com>

* fix scripts and docs for the new dir structure

Signed-off-by: Yashodhan Joshi <yjdoc2@gmail.com>

---------

Signed-off-by: Yashodhan Joshi <yjdoc2@gmail.com>
  • Loading branch information
YJDoc2 authored Oct 10, 2023
1 parent 2cc0249 commit 80f1f36
Show file tree
Hide file tree
Showing 71 changed files with 20 additions and 18 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/integration_tests_validation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ jobs:
with:
files: |
.github/workflows/integration_tests_validation.yaml
tests/rust-integration-tests/**
tests/runtimetest/**
tests/test_framework/**
tests/integration_test/**
files_ignore: |
**.md
- name: List all changed files
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
resolver = "2"
members = ["tests/rust-integration-tests/*", "crates/*", "tools/*"]
members = ["tests/runtimetest/","tests/integration_test/","tests/test_framework/","crates/*", "tools/*"]

[profile.release]
lto = true
2 changes: 1 addition & 1 deletion docs/src/developer/e2e/integration_test.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# integration_test

**Note** that these tests resides in `/tests/rust-integration-tests/integration_test/` at the time of writing.
**Note** that these tests resides in `/tests/integration_test/` at the time of writing.

This crate contains the Rust port of OCI-runtime tools integration tests, which are used to test if the runtime works as per the OCI spec or not. Initially youki used the original implementation of these test provided in the OCI repository [here](https://github.com/opencontainers/runtime-tools/tree/master/validation). But those tests are written in Go, which made the developers depend on two language environments Rust and Go to compile youki and test it. The Validation tests themselves also have an optional dependency on node js to parse their output, which can make it a third language dependency.

Expand Down
2 changes: 1 addition & 1 deletion docs/src/developer/e2e/runtimetest.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Runtime Test

**Note** that these tests resides in /tests/rust-integration-tests/runtimetest at the time of writing.
**Note** that these tests resides in /tests/runtimetest at the time of writing.

This crate provides a binary which is used by integration tests to verify that the restrictions and constraints applied to the container are upheld by the container process, from inside the container process. This runs the tests one-by-one, and the failing test prints the error to the stderr.

Expand Down
14 changes: 7 additions & 7 deletions docs/src/developer/e2e/rust_oci_test.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ We will not go into detail here, but will explain how to write and add a new tes
<p>

```rust,no_run,noplayground
{{#include ../../../../tests/rust-integration-tests/integration_test/src/tests/example/hello_world.rs}}
{{#include ../../../../tests/integration_test/src/tests/example/hello_world.rs}}
```

</p>
Expand All @@ -33,31 +33,31 @@ We will not go into detail here, but will explain how to write and add a new tes
Therefore, it is common practice here to write an OCI Runtime Spec that executes `runtimetest`.

```rust,no_run,noplayground
{{#include ../../../../tests/rust-integration-tests/integration_test/src/tests/example/hello_world.rs:get_example_spec}}
{{#include ../../../../tests/integration_test/src/tests/example/hello_world.rs:get_example_spec}}
```

2. Prepare a function that returns a `TestResult`, which represents the result of the test.

```rust,no_run,noplayground
{{#include ../../../../tests/rust-integration-tests/integration_test/src/tests/example/hello_world.rs:example_test}}
{{#include ../../../../tests/integration_test/src/tests/example/hello_world.rs:example_test}}
```

3. Create a `TestGroup` and register a test case you created

```rust,no_run,noplayground
{{#include ../../../../tests/rust-integration-tests/integration_test/src/tests/example/hello_world.rs:get_example_test}}
{{#include ../../../../tests/integration_test/src/tests/example/hello_world.rs:get_example_test}}
```

4. Register the `TestGroup` you created to a `TestManager`

```rust,no_run,noplayground
{{#include ../../../../tests/rust-integration-tests/integration_test/src/main.rs:register_example_test}}
{{#include ../../../../tests/integration_test/src/main.rs:register_example_test}}
```

5. Write the validation you want to run within a test container
```rust,no_run,noplayground
{{#include ../../../../tests/rust-integration-tests/runtimetest/src/main.rs:example_runtimetest_main}}
{{#include ../../../../tests/runtimetest/src/main.rs:example_runtimetest_main}}
```
```rust,no_run,noplayground
{{#include ../../../../tests/rust-integration-tests/runtimetest/src/tests.rs:example_hello_world}}
{{#include ../../../../tests/runtimetest/src/tests.rs:example_hello_world}}
```
2 changes: 1 addition & 1 deletion docs/src/developer/e2e/test_framework.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# test_framework

**Note** that these tests resides in /tests/rust-integration-tests/test_framework at the time of writing.
**Note** that these tests resides in /tests/test_framework at the time of writing.

This crate contains the testing framework specifically developed for porting the OCI integration test to rust. This contains structs to represent the individual tests, group of tests and a test manager that has responsibility to run tests. This Also exposes traits which can be used to implement custom test structs or test group structs if needed.

Expand Down
2 changes: 1 addition & 1 deletion docs/src/developer/runtimetest.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Runtime Test

**Note** that these tests resides in /tests/rust-integration-tests/runtimetest at the time of writing.
**Note** that these tests resides in /tests/runtimetest at the time of writing.

This crate provides a binary which is used by integration tests to verify that the restrictions and constraints applied to the container are upheld by the container process, from inside the container process. This runs the tests one-by-one, and the failing test prints the error to the stderr.

Expand Down
2 changes: 1 addition & 1 deletion scripts/rust_integration_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ROOT=${2-$(git rev-parse --show-toplevel)}
LOGFILE="${ROOT}/test.log"

if [ ! -f ${ROOT}/bundle.tar.gz ]; then
cp ${ROOT}/tests/rust-integration-tests/integration_test/bundle.tar.gz ${ROOT}/bundle.tar.gz
cp ${ROOT}/tests/integration_test/bundle.tar.gz ${ROOT}/bundle.tar.gz
fi
touch ${LOGFILE}

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ edition = "2021"
anyhow = "1.0"
chrono = { version = "0.4", default-features = false, features = ["clock"] }
flate2 = "1.0"
libcgroups = { path = "../../../crates/libcgroups" }
libcontainer = { path = "../../../crates/libcontainer" }
libcgroups = { path = "../../crates/libcgroups" }
libcontainer = { path = "../../crates/libcontainer" }
nix = "0.27.1"
num_cpus = "1.16"
oci-spec = { version = "0.6.1", features = ["runtime"] }
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,9 @@ fn check_recursive_rsymfollow() -> TestResult {

/// this mount test how to work?
/// 1. Create mount_options based on the mount properties of the test
/// 2. Create OCI.Spec content, container one process is runtimetest,(runtimetest is cargo model, file path `tests/rust-integration-tests/runtimetest/`)
/// 2. Create OCI.Spec content, container one process is runtimetest,(runtimetest is cargo model, file path `tests/runtimetest/`)
/// 3. inside container to check if the actual mount matches the spec, (spec https://man7.org/linux/man-pages/man2/mount_setattr.2.html),
/// eg. tests/rust-integration-tests/runtimetest/src/tests.rs
/// eg. tests/runtimetest/src/tests.rs
pub fn get_mounts_recursive_test() -> TestGroup {
let rro_test = Test::new("rro_test", Box::new(check_recursive_readonly));
let rnosuid_test = Test::new("rnosuid_test", Box::new(check_recursive_nosuid));
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 80f1f36

Please sign in to comment.