|
| 1 | +# composefs-rs integration tests |
| 2 | + |
| 3 | +Integration tests for `cfsctl` that exercise the CLI as a subprocess. |
| 4 | +Unlike the workspace's unit tests, these run the actual binary against |
| 5 | +real repositories and (optionally) real kernels with fs-verity. |
| 6 | + |
| 7 | +The test binary uses `libtest-mimic` with `linkme` distributed slices |
| 8 | +instead of `#[test]`, following the same pattern as |
| 9 | +[bcvk](https://github.com/bootc-dev/bcvk). |
| 10 | + |
| 11 | +## Test tiers |
| 12 | + |
| 13 | +**CLI tests** (`test_*`) run on the host without root. They pass |
| 14 | +`--insecure` to skip fs-verity and use temp dirs for repositories. |
| 15 | +These are fast and need no special setup. |
| 16 | + |
| 17 | +**Privileged tests** (`privileged_*`) need root and real fs-verity |
| 18 | +support. They create loopback ext4 filesystems with the verity feature |
| 19 | +and run `cfsctl` without `--insecure`. When run on the host (not as |
| 20 | +root), each test automatically re-executes itself inside a |
| 21 | +[bcvk](https://github.com/bootc-dev/bcvk) ephemeral VM — no separate |
| 22 | +wrapper functions needed. Set `COMPOSEFS_TEST_IMAGE` to enable this. |
| 23 | + |
| 24 | +## Running |
| 25 | + |
| 26 | +```sh |
| 27 | +# Fast CLI tests only (no root, no VM) |
| 28 | +just integration-unprivileged |
| 29 | + |
| 30 | +# Everything, privileged tests auto-dispatch to bcvk VM |
| 31 | +just integration-container |
| 32 | +``` |
| 33 | + |
| 34 | +The container image is built from the repo's `Containerfile` and |
| 35 | +includes both `cfsctl` and `cfsctl-integration-tests` at `/usr/bin/`. |
| 36 | +It's based on `centos-bootc:stream10` so bcvk can boot it as a VM. |
| 37 | + |
| 38 | +## Running privileged tests without bcvk |
| 39 | + |
| 40 | +If you have root and a kernel with fs-verity support (5.4+), you can |
| 41 | +skip the VM dispatch entirely. The tests create loopback ext4 |
| 42 | +filesystems with the verity feature, so you need `mkfs.ext4` and |
| 43 | +`mount` available. |
| 44 | + |
| 45 | +**Direct execution as root** (e.g. inside a VM, a privileged |
| 46 | +container, or a test machine): |
| 47 | + |
| 48 | +```sh |
| 49 | +cfsctl-integration-tests privileged_ |
| 50 | +``` |
| 51 | + |
| 52 | +Or from the workspace: |
| 53 | + |
| 54 | +```sh |
| 55 | +sudo CFSCTL_PATH=$(pwd)/target/debug/cfsctl cargo run -p integration-tests -- privileged_ |
| 56 | +``` |
| 57 | + |
| 58 | +**Inside a privileged container** — useful on hosts without native |
| 59 | +fs-verity or when you don't want to install dependencies locally: |
| 60 | + |
| 61 | +```sh |
| 62 | +podman run --privileged -v $(pwd):/src:Z -w /src \ |
| 63 | + quay.io/fedora/fedora:41 \ |
| 64 | + bash -c 'dnf -y install cargo composefs e2fsprogs && \ |
| 65 | + cargo build -p cfsctl -p integration-tests && \ |
| 66 | + CFSCTL_PATH=$(pwd)/target/debug/cfsctl \ |
| 67 | + cargo run -p integration-tests -- privileged_' |
| 68 | +``` |
| 69 | + |
| 70 | +### Environment variables |
| 71 | + |
| 72 | +| Variable | Purpose | |
| 73 | +|---|---| |
| 74 | +| `CFSCTL_PATH` | Path to `cfsctl` binary. Auto-detected if not set. | |
| 75 | +| `COMPOSEFS_TEST_IMAGE` | Container image for VM dispatch. Setting this triggers bcvk auto-dispatch for privileged tests. | |
| 76 | +| `BCVK_PATH` | Path to `bcvk` binary. Found in `PATH` if not set. | |
| 77 | +| `COMPOSEFS_IN_VM` | Set automatically inside VMs to prevent recursive dispatch. | |
| 78 | + |
| 79 | +## Adding tests |
| 80 | + |
| 81 | +Define a function returning `anyhow::Result<()>` and register it: |
| 82 | + |
| 83 | +```rust |
| 84 | +fn test_my_feature() -> Result<()> { |
| 85 | + let sh = Shell::new()?; |
| 86 | + let cfsctl = cfsctl()?; |
| 87 | + // ... |
| 88 | + Ok(()) |
| 89 | +} |
| 90 | +integration_test!(test_my_feature); |
| 91 | +``` |
| 92 | + |
| 93 | +For privileged tests, call `require_privileged()` at the top. This |
| 94 | +handles both execution paths — running directly as root, or |
| 95 | +re-dispatching into a VM: |
| 96 | + |
| 97 | +```rust |
| 98 | +fn privileged_my_feature() -> Result<()> { |
| 99 | + if require_privileged("privileged_my_feature")?.is_some() { |
| 100 | + return Ok(()); |
| 101 | + } |
| 102 | + // ... test body runs as root with fs-verity ... |
| 103 | + Ok(()) |
| 104 | +} |
| 105 | +integration_test!(privileged_my_feature); |
| 106 | +``` |
0 commit comments