From cbe1fcb8a3ee9caafb437b5a9c4edbe34ae1bf3c Mon Sep 17 00:00:00 2001 From: Steven Presti Date: Thu, 28 Mar 2024 11:03:43 -0400 Subject: [PATCH] wip-stuck in limbo --- lib/src/cli.rs | 23 ++++++++++++++++++++++- lib/src/privtests.rs | 16 ++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/lib/src/cli.rs b/lib/src/cli.rs index 50480abf3..ba97a9d02 100644 --- a/lib/src/cli.rs +++ b/lib/src/cli.rs @@ -2,7 +2,6 @@ //! //! Command line tool to manage bootable ostree-based containers. -use anyhow::Ok; use anyhow::{Context, Result}; use camino::Utf8PathBuf; use cap_std_ext::cap_std; @@ -151,6 +150,10 @@ pub(crate) enum TestingOpts { image: String, blockdev: Utf8PathBuf, }, + // Test set of lints on ostree container + TestBuildLint { + image: String, + }, } /// Deploy and transactionally in-place with bootable container images. @@ -588,3 +591,21 @@ fn test_parse_install_args() { assert!(o.target_opts.target_no_signature_verification); assert_eq!(o.filesystem_opts.root_path.as_str(), "/target"); } + +#[test] +fn test_linting() { + // linting should only occur in side of a container. + match ostree_ext::container_utils::is_ostree_container() { + Ok(result) => { + if !result { + let expected_error_message = "Not in a ostree container, this command only verifies ostree containers."; + + let result = lint(); + assert_eq!(result.err().unwrap().to_string(), expected_error_message, "Error message mismatch"); + } + + }, + Err(_) =>{ + } + } +} \ No newline at end of file diff --git a/lib/src/privtests.rs b/lib/src/privtests.rs index a3a6192c6..c1f264794 100644 --- a/lib/src/privtests.rs +++ b/lib/src/privtests.rs @@ -162,6 +162,18 @@ fn test_install_filesystem(image: &str, blockdev: &Utf8Path) -> Result<()> { Ok(()) } +#[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()?; + + Ok(()) + +} + pub(crate) async fn run(opts: TestingOpts) -> Result<()> { match opts { TestingOpts::RunPrivilegedIntegration {} => { @@ -179,5 +191,9 @@ pub(crate) async fn run(opts: TestingOpts) -> Result<()> { crate::cli::ensure_self_unshared_mount_namespace().await?; tokio::task::spawn_blocking(move || test_install_filesystem(&image, &blockdev)).await? } + TestingOpts::TestBuildLint { image } => { + tokio::task::spawn_blocking(move || test_build_lint(&image)).await? + } + } }