-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #548 from cgwalters/test-improvements
Move install tests shell script into Rust
- Loading branch information
Showing
9 changed files
with
327 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Our integration tests | ||
[package] | ||
name = "tests-integration" | ||
version = "0.1.0" | ||
license = "MIT OR Apache-2.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[[bin]] | ||
name = "tests-integration" | ||
path = "src/tests-integration.rs" | ||
|
||
[dependencies] | ||
anyhow = "1.0.82" | ||
camino = "1.1.6" | ||
cap-std-ext = "4" | ||
clap = { version= "4.5.4", features = ["derive","cargo"] } | ||
fn-error-context = "0.2.1" | ||
libtest-mimic = "0.7.3" | ||
tempfile = "3.10.1" | ||
xshell = { version = "0.2.6" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Integration tests crate | ||
|
||
This crate holds integration tests (as distinct from the regular | ||
Rust unit tests run as part of `cargo test`). | ||
|
||
## Building and running | ||
|
||
`cargo run -p tests-integration` | ||
will work. Note that at the current time all test suites target | ||
an externally built bootc-compatible container image. See | ||
how things are set up in e.g. Github Actions, where we first | ||
run a `podman build` with the bootc git sources. | ||
|
||
## Available suites | ||
|
||
### `host-privileged` | ||
|
||
This suite will run the target container image in a way that expects | ||
full privileges, but is *not* destructive. | ||
|
||
### `install-alongside` | ||
|
||
This suite is *DESTRUCTIVE*, executing the bootc `install to-existing-root` | ||
style flow using the host root. Run it in a transient virtual machine. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use anyhow::Result; | ||
use fn_error_context::context; | ||
use libtest_mimic::Trial; | ||
use xshell::cmd; | ||
|
||
/// Tests that require real root (e.g. CAP_SYS_ADMIN) to do things like | ||
/// create loopback devices, but are *not* destructive. At the current time | ||
/// these tests are defined to reference a bootc container image. | ||
#[context("Hostpriv tests")] | ||
pub(crate) fn run_hostpriv(image: &str, testargs: libtest_mimic::Arguments) -> Result<()> { | ||
// Just leak the image name so we get a static reference as required by the test framework | ||
let image: &'static str = String::from(image).leak(); | ||
let base_args = super::install::BASE_ARGS; | ||
|
||
let tests = [Trial::test("loopback install", move || { | ||
let sh = &xshell::Shell::new()?; | ||
let size = 10 * 1000 * 1000 * 1000; | ||
let mut tmpdisk = tempfile::NamedTempFile::new_in("/var/tmp")?; | ||
tmpdisk.as_file_mut().set_len(size)?; | ||
let tmpdisk = tmpdisk.into_temp_path(); | ||
let tmpdisk = tmpdisk.to_str().unwrap(); | ||
cmd!(sh, "sudo {base_args...} -v {tmpdisk}:/disk {image} bootc install to-disk --via-loopback --skip-fetch-check /disk").run()?; | ||
Ok(()) | ||
})]; | ||
|
||
libtest_mimic::run(&testargs, tests.into()).exit() | ||
} |
Oops, something went wrong.