Forge-runner integration tests build as one binary
Browse files at this commitb49555262dcd04201507575e0ab4c166f4757d2bParent: f7792aa- refactor
- forge-runner integration tests build as one binary
7 changed files +41 -49
- crates/forge-runner/tests/builtin.rs → crates/forge-runner/tests/integration/builtin.rs +2 -25
- crates/forge-runner/tests/integration/common/mod.rs +28 -0
- crates/forge-runner/tests/flow.rs → crates/forge-runner/tests/integration/flow.rs +0 -0
- crates/forge-runner/tests/idmap.rs → crates/forge-runner/tests/integration/idmap.rs +0 -0
- crates/forge-runner/tests/integration/main.rs +9 -0
- crates/forge-runner/tests/sandbox.rs → crates/forge-runner/tests/integration/sandbox.rs +2 -24
- crates/forge-runner/tests/unpack_subuid.rs → crates/forge-runner/tests/integration/unpack_subuid.rs +0 -0
crates/forge-runner/tests/builtin.rs → crates/forge-runner/tests/integration/builtin.rsrenamed+2 -25
| @@ -6,7 +6,6 @@ use std::collections::BTreeMap; | |||
| 6 | use std::fs; | 6 | use std::fs; |
| 7 | use std::future::Future; | 7 | use std::future::Future; |
| 8 | use std::path::{Path, PathBuf}; | 8 | use std::path::{Path, PathBuf}; |
| 9 | -use std::process::Command; | ||
| 10 | use std::time::{Duration, Instant}; | 9 | use std::time::{Duration, Instant}; |
| 11 | 10 | ||
| 12 | use forge_ci::proto::{JobAssignment, Outcome}; | 11 | use forge_ci::proto::{JobAssignment, Outcome}; |
| @@ -20,6 +19,8 @@ use nix::unistd::Pid; | |||
| 20 | use tokio::sync::mpsc; | 19 | use tokio::sync::mpsc; |
| 21 | use tokio_util::sync::CancellationToken; | 20 | use tokio_util::sync::CancellationToken; |
| 22 | 21 | ||
| 22 | +use crate::common::can_run; | ||
| 23 | + | ||
| 23 | /// Hands out a fixed rootfs for every image, with an env that the job can observe. | 24 | /// Hands out a fixed rootfs for every image, with an env that the job can observe. |
| 24 | struct LocalRootfs(PathBuf); | 25 | struct LocalRootfs(PathBuf); |
| 25 | 26 | ||
| @@ -43,30 +44,6 @@ impl ImageSource for LocalRootfs { | |||
| 43 | } | 44 | } |
| 44 | } | 45 | } |
| 45 | 46 | ||
| 46 | -fn userns_available() -> bool { | ||
| 47 | - let max = fs::read_to_string("/proc/sys/user/max_user_namespaces") | ||
| 48 | - .ok() | ||
| 49 | - .and_then(|s| s.trim().parse::<u64>().ok()) | ||
| 50 | - .unwrap_or(0); | ||
| 51 | - if max == 0 { | ||
| 52 | - return false; | ||
| 53 | - } | ||
| 54 | - Command::new("unshare") | ||
| 55 | - .args(["--user", "--map-root-user", "true"]) | ||
| 56 | - .status() | ||
| 57 | - .is_ok_and(|s| s.success()) | ||
| 58 | -} | ||
| 59 | - | ||
| 60 | -/// Skips the test when user namespaces are unavailable. Returns `true` when the test should run. | ||
| 61 | -fn can_run() -> bool { | ||
| 62 | - if userns_available() { | ||
| 63 | - true | ||
| 64 | - } else { | ||
| 65 | - eprintln!("skipping: unprivileged user namespaces are not available on this host"); | ||
| 66 | - false | ||
| 67 | - } | ||
| 68 | -} | ||
| 69 | - | ||
| 70 | fn job(run: &str) -> JobAssignment { | 47 | fn job(run: &str) -> JobAssignment { |
| 71 | JobAssignment { | 48 | JobAssignment { |
| 72 | job_id: "job_01".to_owned(), | 49 | job_id: "job_01".to_owned(), |
crates/forge-runner/tests/integration/common/mod.rsadded+28 -0
| @@ -0,0 +1,28 @@ | |||
| 1 | +//! Support code shared by the integration tests. | ||
| 2 | + | ||
| 3 | +use std::fs; | ||
| 4 | +use std::process::Command; | ||
| 5 | + | ||
| 6 | +fn userns_available() -> bool { | ||
| 7 | + let max = fs::read_to_string("/proc/sys/user/max_user_namespaces") | ||
| 8 | + .ok() | ||
| 9 | + .and_then(|s| s.trim().parse::<u64>().ok()) | ||
| 10 | + .unwrap_or(0); | ||
| 11 | + if max == 0 { | ||
| 12 | + return false; | ||
| 13 | + } | ||
| 14 | + Command::new("unshare") | ||
| 15 | + .args(["--user", "--map-root-user", "true"]) | ||
| 16 | + .status() | ||
| 17 | + .is_ok_and(|s| s.success()) | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +/// Skips the test when user namespaces are unavailable. Returns `true` when the test should run. | ||
| 21 | +pub fn can_run() -> bool { | ||
| 22 | + if userns_available() { | ||
| 23 | + true | ||
| 24 | + } else { | ||
| 25 | + eprintln!("skipping: unprivileged user namespaces are not available on this host"); | ||
| 26 | + false | ||
| 27 | + } | ||
| 28 | +} | ||
crates/forge-runner/tests/flow.rs → crates/forge-runner/tests/integration/flow.rsrenamed+0 -0
crates/forge-runner/tests/idmap.rs → crates/forge-runner/tests/integration/idmap.rsrenamed+0 -0
crates/forge-runner/tests/integration/main.rsadded+9 -0
| @@ -0,0 +1,9 @@ | |||
| 1 | +//! Integration tests for forge-runner, built as a single test binary. | ||
| 2 | + | ||
| 3 | +mod common; | ||
| 4 | + | ||
| 5 | +mod builtin; | ||
| 6 | +mod flow; | ||
| 7 | +mod idmap; | ||
| 8 | +mod sandbox; | ||
| 9 | +mod unpack_subuid; | ||
crates/forge-runner/tests/sandbox.rs → crates/forge-runner/tests/integration/sandbox.rsrenamed+2 -24
| @@ -15,36 +15,14 @@ use forge_runner::config::Limits; | |||
| 15 | use forge_runner::sandbox::SandboxRequest; | 15 | use forge_runner::sandbox::SandboxRequest; |
| 16 | use forge_runner::sandbox::idmap::{IdMap, UsernsMode}; | 16 | use forge_runner::sandbox::idmap::{IdMap, UsernsMode}; |
| 17 | 17 | ||
| 18 | +use crate::common::can_run; | ||
| 19 | + | ||
| 18 | /// Utilities copied into the test rootfs. `sh` is the job shell, and the rest are used by the | 20 | /// Utilities copied into the test rootfs. `sh` is the job shell, and the rest are used by the |
| 19 | /// test scripts. | 21 | /// test scripts. |
| 20 | const BINARIES: &[&str] = &[ | 22 | const BINARIES: &[&str] = &[ |
| 21 | "sh", "id", "cat", "grep", "touch", "sleep", "unshare", "chown", "stat", "mkdir", | 23 | "sh", "id", "cat", "grep", "touch", "sleep", "unshare", "chown", "stat", "mkdir", |
| 22 | ]; | 24 | ]; |
| 23 | 25 | ||
| 24 | -fn userns_available() -> bool { | ||
| 25 | - let max = fs::read_to_string("/proc/sys/user/max_user_namespaces") | ||
| 26 | - .ok() | ||
| 27 | - .and_then(|s| s.trim().parse::<u64>().ok()) | ||
| 28 | - .unwrap_or(0); | ||
| 29 | - if max == 0 { | ||
| 30 | - return false; | ||
| 31 | - } | ||
| 32 | - Command::new("unshare") | ||
| 33 | - .args(["--user", "--map-root-user", "true"]) | ||
| 34 | - .status() | ||
| 35 | - .is_ok_and(|s| s.success()) | ||
| 36 | -} | ||
| 37 | - | ||
| 38 | -/// Skips the test when user namespaces are unavailable. Returns `true` when the test should run. | ||
| 39 | -fn can_run() -> bool { | ||
| 40 | - if userns_available() { | ||
| 41 | - true | ||
| 42 | - } else { | ||
| 43 | - eprintln!("skipping: unprivileged user namespaces are not available on this host"); | ||
| 44 | - false | ||
| 45 | - } | ||
| 46 | -} | ||
| 47 | - | ||
| 48 | /// The shared libraries `ldd` reports for `binary`, as absolute host paths. | 26 | /// The shared libraries `ldd` reports for `binary`, as absolute host paths. |
| 49 | fn shared_libs(binary: &Path) -> Vec<PathBuf> { | 27 | fn shared_libs(binary: &Path) -> Vec<PathBuf> { |
| 50 | let Ok(out) = Command::new("ldd").arg(binary).output() else { | 28 | let Ok(out) = Command::new("ldd").arg(binary).output() else { |
crates/forge-runner/tests/unpack_subuid.rs → crates/forge-runner/tests/integration/unpack_subuid.rsrenamed+0 -0