phoebus_os/installer-rs/crates/phoebus-installer/tests/plan_golden.rs
Phoebus 4c59a1f3ad test(rust): replace the Bash parity test with golden plan tests
parity.rs compared the Rust plan to the Bash installer. The Bash tree is
being retired, so pin the exact Rust plan and destructive preview to golden
files instead (UPDATE_GOLDEN=1 to regenerate).
2026-09-20 03:56:57 -07:00

73 lines
2.5 KiB
Rust

//! Golden-file tests for the Rust installation plan.
//!
//! These pin the exact human-readable plan and destructive preview for a fixed
//! configuration, replacing the Bash/Rust `parity.rs` comparison. Regenerate
//! with `UPDATE_GOLDEN=1 cargo test -p phoebus-installer --test plan_golden`
//! after an intentional plan change, then review the diff.
use std::path::PathBuf;
use phoebus_core::{InstallConfig, InstallPlan};
const CONFIG: &str = "\
HOSTNAME='paritybox'\n\
USERNAME='parityuser'\n\
LOCALE='en_US.UTF-8'\n\
TIMEZONE='UTC'\n\
KEYMAP='us'\n\
TARGET_DISK='/dev/vda'\n\
EFI_SIZE_MIB='1024'\n\
FILESYSTEM='btrfs'\n\
ENCRYPTION='luks2'\n\
COMPRESS='zstd:3'\n\
KERNEL_PROFILE='safe'\n\
KERNEL_CONSOLE='console=tty0'\n\
PACKAGE_POLICY='balanced'\n\
DESKTOP_PROFILE='dwl'\n\
BTRFS_SUBVOLS='@ @home @var @snapshots @swap'\n";
fn sample_config() -> InstallConfig {
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("golden.conf");
std::fs::write(&path, CONFIG).unwrap();
InstallConfig::load_from_path(&path).expect("load golden configuration")
}
fn check_golden(name: &str, actual: &str) {
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("tests/golden")
.join(name);
if std::env::var("UPDATE_GOLDEN").as_deref() == Ok("1") {
std::fs::create_dir_all(path.parent().unwrap()).unwrap();
std::fs::write(&path, actual).unwrap();
return;
}
let expected = std::fs::read_to_string(&path)
.unwrap_or_else(|_| panic!("missing golden file {name}; run with UPDATE_GOLDEN=1"));
assert_eq!(actual, expected, "output drifted from tests/golden/{name}");
}
#[test]
fn plan_output_matches_golden() {
let config = sample_config();
let actual = InstallPlan::for_config(&config).render_human(&config, None);
check_golden("plan.txt", &actual);
}
#[test]
fn destructive_preview_matches_golden() {
let config = sample_config();
let actual = InstallPlan::for_config(&config)
.destructive_preview(&config, "NAME SIZE TYPE\nvda 30G disk");
check_golden("destructive-preview.txt", &actual);
}
#[test]
fn golden_config_is_valid_and_ordered() {
// Guard against a golden that silently stops exercising the real path.
let config = sample_config();
assert_eq!(config.system.hostname, "paritybox");
let steps = InstallPlan::for_config(&config).steps;
assert_eq!(steps.first().map(|s| s.name()), Some("storage_prepare"));
assert_eq!(steps.last().map(|s| s.name()), Some("finalize"));
}