Skip to content

Commit

Permalink
wip: tweaking tests, and getting understanding of cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
prestist committed May 2, 2024
1 parent cbe1fcb commit ddd5167
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions lib/src/privtests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use camino::Utf8Path;
use fn_error_context::context;
use rustix::fd::AsFd;
use xshell::{cmd, Shell};

use crate::blockdev::LoopbackDevice;
use crate::install::config::InstallConfiguration;

Expand Down Expand Up @@ -164,14 +163,34 @@ fn test_install_filesystem(image: &str, blockdev: &Utf8Path) -> 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();
let _test_2_result = match more_then_one_kernel_result {
Ok(_) => Err(anyhow::anyhow!("Expected error, got none")),
Err(_) => Ok(())
};

// Container Cleanup
cmd!(sh, "podman rm -f test").run()?;

_test_1_result?;
_test_2_result?;
Ok(())

}

pub(crate) async fn run(opts: TestingOpts) -> Result<()> {
Expand Down

0 comments on commit ddd5167

Please sign in to comment.