Skip to content

Commit

Permalink
tests: Add a new booted-host suite
Browse files Browse the repository at this point in the history
This runs from tmt.

Signed-off-by: Colin Walters <walters@verbum.org>
  • Loading branch information
cgwalters committed Jun 21, 2024
1 parent 28adfc5 commit 8245f44
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
7 changes: 6 additions & 1 deletion plans/integration.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ provision:
summary: Basic smoke test
execute:
how: tmt
script: bootc status
# This just turns around and runs a Rust-based test framework
# (part of tests-integration) that's been injected into the default
# container image.
script: |
bootc status
bootc-integration-tests booted-host
25 changes: 25 additions & 0 deletions tests-integration/src/bootedhost.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use anyhow::Result;
use fn_error_context::context;
use xshell::cmd;

use super::new_test;

fn test_status() -> Result<()> {
let sh = &xshell::Shell::new()?;
let host: serde_json::Value = serde_json::from_str(&cmd!(sh, "bootc status --json").read()?)?;
let status = host.get("status").unwrap();
let booted = status.get("booted").unwrap();
assert!(booted.get("image").is_some());
Ok(())
}

/// Tests that assume we're in a bootc host system.
#[context("Host booted tests")]
pub(crate) fn run_booted_host(mut testargs: libtest_mimic::Arguments) -> Result<()> {
// Force all of these tests to be serial because they mutate global state
testargs.test_threads = Some(1);

let tests = [new_test("status", test_status)];

libtest_mimic::run(&testargs, tests.into()).exit()
}
5 changes: 1 addition & 4 deletions tests-integration/src/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ use std::process::Command;

use anyhow::{Context, Result};
use fn_error_context::context;
use libtest_mimic::Trial;
use xshell::{cmd, Shell};

fn new_test(description: &'static str, f: fn() -> anyhow::Result<()>) -> libtest_mimic::Trial {
Trial::test(description, move || f().map_err(Into::into))
}
use super::new_test;

pub(crate) fn test_bootc_status() -> Result<()> {
let sh = Shell::new()?;
Expand Down
15 changes: 15 additions & 0 deletions tests-integration/src/tests-integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,21 @@ use camino::Utf8PathBuf;
use cap_std_ext::cap_std::{self, fs::Dir};
use clap::Parser;

mod bootedhost;
mod container;
mod hostpriv;
mod install;
mod runvm;
mod selinux;

/// Generic wrapper for creating a test
pub(crate) fn new_test(
description: &'static str,
f: fn() -> anyhow::Result<()>,
) -> libtest_mimic::Trial {
libtest_mimic::Trial::test(description, move || f().map_err(Into::into))
}

#[derive(Debug, Parser)]
#[clap(name = "bootc-integration-tests", version, rename_all = "kebab-case")]
pub(crate) enum Opt {
Expand All @@ -27,6 +36,11 @@ pub(crate) enum Opt {
#[clap(flatten)]
testargs: libtest_mimic::Arguments,
},
/// Tests that operate on a booted host system; may be destructive!
BootedHost {
#[clap(flatten)]
testargs: libtest_mimic::Arguments,
},
/// Tests which should be executed inside an existing bootc container image.
/// These should be nondestructive.
Container {
Expand All @@ -50,6 +64,7 @@ fn main() {
let r = match opt {
Opt::InstallAlongside { image, testargs } => install::run_alongside(&image, testargs),
Opt::HostPrivileged { image, testargs } => hostpriv::run_hostpriv(&image, testargs),
Opt::BootedHost { testargs } => bootedhost::run_booted_host(testargs),
Opt::Container { testargs } => container::run(testargs),
Opt::RunVM(opts) => runvm::run(opts),
Opt::VerifySELinux { rootfs, warn } => {
Expand Down

0 comments on commit 8245f44

Please sign in to comment.