summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorHermes Agent <hermes@localhost>2026-08-12 01:06:37 +0000
committerHermes Agent <hermes@localhost>2026-08-12 01:06:37 +0000
commit915fcc5efbf45d8adee870cfbe2a25e466454a2f (patch)
treed5fdf2a745f905bd5fcce2ddac14d3e1c7a852e9 /tests
parentfacbf9629f45b95d34a4d0844e617f87a35be5ff (diff)
Isolate Hasher behind typed installer adapter
Diffstat (limited to 'tests')
-rw-r--r--tests/package_installer.rs72
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/package_installer.rs b/tests/package_installer.rs
new file mode 100644
index 0000000..622d378
--- /dev/null
+++ b/tests/package_installer.rs
@@ -0,0 +1,72 @@
+use std::path::PathBuf;
+
+use alt_controller_image::hasher::{CommandRunner, HasherInstaller, Invocation};
+use alt_controller_image::package_installer::{AptConfig, PackageInstaller, PackageRequest};
+
+#[derive(Default)]
+struct RecordingRunner {
+ invocations: std::cell::RefCell<Vec<Invocation>>,
+}
+
+impl CommandRunner for RecordingRunner {
+ fn run(&self, invocation: Invocation) -> anyhow::Result<()> {
+ self.invocations.borrow_mut().push(invocation);
+ Ok(())
+ }
+}
+
+#[test]
+fn hasher_installer_passes_typed_request_to_initroot_and_install_commands() {
+ let runner = RecordingRunner::default();
+ let installer = HasherInstaller::new(runner);
+ let request = PackageRequest::new(
+ "/build/work",
+ AptConfig::new("profiles/apt.conf").expect("valid apt config path"),
+ ["basesystem", "make-initrd"],
+ ["^kernel-image-rt$"],
+ )
+ .expect("valid package request");
+
+ installer.install(&request).expect("installation succeeds");
+ let invocations = &installer.runner().invocations.borrow();
+
+ assert_eq!(
+ invocations.as_slice(),
+ [
+ Invocation::new(
+ "hsh",
+ [
+ "--mountpoints=/proc",
+ "--initroot-only",
+ "--apt-config",
+ "profiles/apt.conf",
+ "--workdir",
+ "/build/work",
+ ],
+ ),
+ Invocation::new(
+ "hsh-install",
+ [
+ "--mountpoints=/proc",
+ "--workdir",
+ "/build/work",
+ "^kernel-image-rt$",
+ "basesystem",
+ "make-initrd",
+ ],
+ ),
+ ]
+ );
+}
+
+#[test]
+fn package_request_rejects_empty_packages_and_unsafe_apt_config_paths() {
+ assert!(AptConfig::new("").is_err());
+ assert!(PackageRequest::new(
+ PathBuf::from("work"),
+ AptConfig::new("profiles/apt.conf").expect("valid apt config"),
+ ["basesystem", ""],
+ std::iter::empty::<&str>(),
+ )
+ .is_err());
+}