diff options
| author | Hermes Agent <hermes@localhost> | 2026-08-12 01:44:59 +0000 |
|---|---|---|
| committer | Hermes Agent <hermes@localhost> | 2026-08-12 01:44:59 +0000 |
| commit | 04c6c5af37d9eac00a2bba2eaba1ec0836834633 (patch) | |
| tree | 6c1f16cce9963dbd8bb7d1791e9c253309d37678 /tests | |
| parent | 9acf451473989fa868e21d2d6ff59cf3fb445562 (diff) | |
Collect semantic facts from native artifacts
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/compare.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/compare.rs b/tests/compare.rs index a4f0a32..b11d288 100644 --- a/tests/compare.rs +++ b/tests/compare.rs @@ -1,7 +1,10 @@ use alt_controller_image::compare::{Change, SemanticDifference, compare}; +use alt_controller_image::archive::NativeTarWriter; use alt_controller_image::manifest::{ ArchiveMemberRecord, ArtifactManifest, FileRecord, InitrdRecord, PackageRecord, ServiceRecord, }; +use std::fs; +use std::os::unix::fs::symlink; use tempfile::tempdir; fn baseline() -> ArtifactManifest { @@ -71,3 +74,49 @@ fn rejects_duplicate_semantic_keys() { assert!(error.to_string().contains("duplicate package record")); } + +#[test] +fn collects_semantic_facts_from_native_rootfs_and_tar_artifact() { + let fixture = tempdir().expect("temporary directory"); + let rootfs = fixture.path().join("rootfs"); + fs::create_dir_all(rootfs.join("etc/systemd/system/multi-user.target.wants")) + .expect("create service state directory"); + fs::write(rootfs.join("etc/controller.conf"), "controller\n").expect("write file"); + symlink("controller.conf", rootfs.join("etc/controller-link")).expect("write symlink"); + symlink( + "/usr/lib/systemd/system/controller.service", + rootfs.join("etc/systemd/system/multi-user.target.wants/controller.service"), + ) + .expect("enable service"); + let artifact = fixture.path().join("controller.tar"); + NativeTarWriter::new() + .write(&rootfs, &artifact) + .expect("write native tar"); + + let manifest = ArtifactManifest::collect( + &rootfs, + vec![PackageRecord::new("controller", "1.0")], + Some(InitrdRecord::new("boot/initrd-rt.img", "digest")), + &artifact, + ) + .expect("collect semantic facts"); + + assert_eq!(manifest.packages, vec![PackageRecord::new("controller", "1.0")]); + assert!(manifest.files.iter().any(|record| record == &FileRecord::file( + "etc/controller.conf", + "2d5c759b2b539229e09d362e8dbe0ae410ff8c9ece6038624458724520683f5b", + ))); + assert!(manifest + .files + .iter() + .any(|record| record == &FileRecord::symlink("etc/controller-link", "controller.conf"))); + assert_eq!(manifest.services, vec![ServiceRecord::new("controller.service", true)]); + assert!(manifest + .archive_members + .iter() + .any(|record| record == &ArchiveMemberRecord::new("etc/controller.conf", "file"))); + assert!(manifest + .archive_members + .iter() + .any(|record| record == &ArchiveMemberRecord::new("etc/controller-link", "symlink"))); +} |