diff --git a/crates/forge-runner/tests/builtin.rs b/crates/forge-runner/tests/integration/builtin.rs similarity index 94% rename from crates/forge-runner/tests/builtin.rs rename to crates/forge-runner/tests/integration/builtin.rs index 2f841b2..b569211 100644 --- a/crates/forge-runner/tests/builtin.rs +++ b/crates/forge-runner/tests/integration/builtin.rs @@ -6,7 +6,6 @@ use std::collections::BTreeMap; use std::fs; use std::future::Future; use std::path::{Path, PathBuf}; -use std::process::Command; use std::time::{Duration, Instant}; use forge_ci::proto::{JobAssignment, Outcome}; @@ -20,6 +19,8 @@ use nix::unistd::Pid; use tokio::sync::mpsc; use tokio_util::sync::CancellationToken; +use crate::common::can_run; + /// Hands out a fixed rootfs for every image, with an env that the job can observe. struct LocalRootfs(PathBuf); @@ -43,30 +44,6 @@ impl ImageSource for LocalRootfs { } } -fn userns_available() -> bool { - let max = fs::read_to_string("/proc/sys/user/max_user_namespaces") - .ok() - .and_then(|s| s.trim().parse::().ok()) - .unwrap_or(0); - if max == 0 { - return false; - } - Command::new("unshare") - .args(["--user", "--map-root-user", "true"]) - .status() - .is_ok_and(|s| s.success()) -} - -/// Skips the test when user namespaces are unavailable. Returns `true` when the test should run. -fn can_run() -> bool { - if userns_available() { - true - } else { - eprintln!("skipping: unprivileged user namespaces are not available on this host"); - false - } -} - fn job(run: &str) -> JobAssignment { JobAssignment { job_id: "job_01".to_owned(), diff --git a/crates/forge-runner/tests/integration/common/mod.rs b/crates/forge-runner/tests/integration/common/mod.rs new file mode 100644 index 0000000..fe6d372 --- /dev/null +++ b/crates/forge-runner/tests/integration/common/mod.rs @@ -0,0 +1,28 @@ +//! Support code shared by the integration tests. + +use std::fs; +use std::process::Command; + +fn userns_available() -> bool { + let max = fs::read_to_string("/proc/sys/user/max_user_namespaces") + .ok() + .and_then(|s| s.trim().parse::().ok()) + .unwrap_or(0); + if max == 0 { + return false; + } + Command::new("unshare") + .args(["--user", "--map-root-user", "true"]) + .status() + .is_ok_and(|s| s.success()) +} + +/// Skips the test when user namespaces are unavailable. Returns `true` when the test should run. +pub fn can_run() -> bool { + if userns_available() { + true + } else { + eprintln!("skipping: unprivileged user namespaces are not available on this host"); + false + } +} diff --git a/crates/forge-runner/tests/flow.rs b/crates/forge-runner/tests/integration/flow.rs similarity index 100% rename from crates/forge-runner/tests/flow.rs rename to crates/forge-runner/tests/integration/flow.rs diff --git a/crates/forge-runner/tests/idmap.rs b/crates/forge-runner/tests/integration/idmap.rs similarity index 100% rename from crates/forge-runner/tests/idmap.rs rename to crates/forge-runner/tests/integration/idmap.rs diff --git a/crates/forge-runner/tests/integration/main.rs b/crates/forge-runner/tests/integration/main.rs new file mode 100644 index 0000000..9dea082 --- /dev/null +++ b/crates/forge-runner/tests/integration/main.rs @@ -0,0 +1,9 @@ +//! Integration tests for forge-runner, built as a single test binary. + +mod common; + +mod builtin; +mod flow; +mod idmap; +mod sandbox; +mod unpack_subuid; diff --git a/crates/forge-runner/tests/sandbox.rs b/crates/forge-runner/tests/integration/sandbox.rs similarity index 96% rename from crates/forge-runner/tests/sandbox.rs rename to crates/forge-runner/tests/integration/sandbox.rs index d10a486..a57240e 100644 --- a/crates/forge-runner/tests/sandbox.rs +++ b/crates/forge-runner/tests/integration/sandbox.rs @@ -15,36 +15,14 @@ use forge_runner::config::Limits; use forge_runner::sandbox::SandboxRequest; use forge_runner::sandbox::idmap::{IdMap, UsernsMode}; +use crate::common::can_run; + /// Utilities copied into the test rootfs. `sh` is the job shell, and the rest are used by the /// test scripts. const BINARIES: &[&str] = &[ "sh", "id", "cat", "grep", "touch", "sleep", "unshare", "chown", "stat", "mkdir", ]; -fn userns_available() -> bool { - let max = fs::read_to_string("/proc/sys/user/max_user_namespaces") - .ok() - .and_then(|s| s.trim().parse::().ok()) - .unwrap_or(0); - if max == 0 { - return false; - } - Command::new("unshare") - .args(["--user", "--map-root-user", "true"]) - .status() - .is_ok_and(|s| s.success()) -} - -/// Skips the test when user namespaces are unavailable. Returns `true` when the test should run. -fn can_run() -> bool { - if userns_available() { - true - } else { - eprintln!("skipping: unprivileged user namespaces are not available on this host"); - false - } -} - /// The shared libraries `ldd` reports for `binary`, as absolute host paths. fn shared_libs(binary: &Path) -> Vec { let Ok(out) = Command::new("ldd").arg(binary).output() else { diff --git a/crates/forge-runner/tests/unpack_subuid.rs b/crates/forge-runner/tests/integration/unpack_subuid.rs similarity index 100% rename from crates/forge-runner/tests/unpack_subuid.rs rename to crates/forge-runner/tests/integration/unpack_subuid.rs