From f63ebe89b114754d754595929234e16d9bb806f7 Mon Sep 17 00:00:00 2001 From: Steven Presti Date: Thu, 25 Apr 2024 14:47:42 -0400 Subject: [PATCH] wip: tweaking tests, and getting understanding of cmd --- lib/src/cli.rs | 3 ++- lib/src/privtests.rs | 30 ++++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/lib/src/cli.rs b/lib/src/cli.rs index 1d722e44d..d1a181fcb 100644 --- a/lib/src/cli.rs +++ b/lib/src/cli.rs @@ -627,7 +627,8 @@ fn lint() -> Result<()> { } let root = cap_std::fs::Dir::open_ambient_dir("/", cap_std::ambient_authority())?; - ostree_ext::bootabletree::find_kernel_dir_fs(&root)?; + let result = ostree_ext::bootabletree::find_kernel_dir_fs(&root)?; + tracing::debug!("Found kernel: {:?}", result); return Ok(()); } diff --git a/lib/src/privtests.rs b/lib/src/privtests.rs index dfe9c8d5c..05fb26a9c 100644 --- a/lib/src/privtests.rs +++ b/lib/src/privtests.rs @@ -9,7 +9,6 @@ use cap_std_ext::cap_std::fs::Dir; use fn_error_context::context; use rustix::fd::AsFd; use xshell::{cmd, Shell}; - use crate::blockdev::LoopbackDevice; use crate::install::config::InstallConfiguration; @@ -198,14 +197,33 @@ fn verify_selinux_recurse(root: &Dir, path: &mut PathBuf, warn: bool) -> Result< #[context("Container tests")] fn test_build_lint(image: &str) -> Result<()> { - let sh = Shell::new()?; - cmd!(sh, "podman run --rm --privileged --pid=host --env=RUST_LOG -v /usr/bin/bootc:/usr/bin/bootc {image} bootc build-lint").run()?; - let copy_kernel = "bootc build-lint"; - cmd!(sh, "podman run --rm --privileged --pid=host --env=RUST_LOG -v /usr/bin/bootc:/usr/bin/bootc {image} {copy_kernel}").run()?; + let sh = Shell::new()?; + // Smoke test of build_lint + let _test_1_result = cmd!(sh, "podman run --rm --privileged --pid=host --env=RUST_LOG -v /usr/bin/bootc:/usr/bin/bootc {image} bootc build-lint").run(); + + // Setup for multiple kernels lint test + cmd!(sh, "podman run -dt --name test --privileged --pid=host --env=RUST_LOG -v /usr/bin/bootc:/usr/bin/bootc {image} bash").run()?; + let kernel_name = cmd!(sh, "podman exec test bash -c 'ls /usr/lib/modules | tail -n -1'" ).read()?; + Command::new("podman") + .arg("exec") + .arg("test") + .arg("bash") + .arg("-c") + .arg(format!("sudo cp -r /usr/lib/modules/{} /usr/lib/modules/delete-me", kernel_name)) + .output()?; + let more_then_one_kernel_result = cmd!(sh, "podman exec test bash -c 'bootc build-lint'").read_stderr(); + // Container Cleanup + cmd!(sh, "podman rm -f test").run()?; + + _test_1_result?; + if let Err(e) = more_then_one_kernel_result { + assert!(e.to_string().contains("bootc build-lint")); + } else { + assert!(false, "Expected error, got none"); + } Ok(()) - } pub(crate) async fn run(opts: TestingOpts) -> Result<()> {