diff options
| author | Hermes Agent <hermes@localhost> | 2026-08-12 02:11:06 +0000 |
|---|---|---|
| committer | Hermes Agent <hermes@localhost> | 2026-08-12 02:11:06 +0000 |
| commit | 0d60d812c4dcf78a18dcc59325dc1ec609cf8eb8 (patch) | |
| tree | 326a4dc80cc81d87bbae8b4537c9e47f5a04c8bb | |
| parent | 271ccc76ad22436b7e0d5291168a5d18c57bb77b (diff) | |
Distinguish initrd additions and removals
| -rw-r--r-- | src/compare.rs | 9 | ||||
| -rw-r--r-- | tests/compare.rs | 27 |
2 files changed, 34 insertions, 2 deletions
diff --git a/src/compare.rs b/src/compare.rs index 7088886..8b59c1c 100644 --- a/src/compare.rs +++ b/src/compare.rs @@ -70,8 +70,13 @@ pub fn compare(left: &ArtifactManifest, right: &ArtifactManifest) -> ComparisonR compare_records(&left.files, &right.files, |record| &record.path, |path, change| { SemanticDifference::File { path: path.to_owned(), change } }, &mut differences); - if left.initrd != right.initrd { - differences.push(SemanticDifference::Initrd { change: Change::Changed }); + match (&left.initrd, &right.initrd) { + (None, Some(_)) => differences.push(SemanticDifference::Initrd { change: Change::Added }), + (Some(_), None) => differences.push(SemanticDifference::Initrd { change: Change::Removed }), + (Some(left), Some(right)) if left != right => { + differences.push(SemanticDifference::Initrd { change: Change::Changed }); + } + _ => {} } compare_records(&left.services, &right.services, |record| &record.name, |name, change| { SemanticDifference::Service { name: name.to_owned(), change } diff --git a/tests/compare.rs b/tests/compare.rs index 59b62cb..0853572 100644 --- a/tests/compare.rs +++ b/tests/compare.rs @@ -51,6 +51,33 @@ fn compares_added_removed_and_changed_semantic_records() { } #[test] +fn distinguishes_added_and_removed_initrd_records() { + let without_initrd = ArtifactManifest::new(vec![], vec![], None, vec![], vec![]) + .expect("valid manifest without initrd"); + let with_initrd = ArtifactManifest::new( + vec![], + vec![], + Some(InitrdRecord::new("boot/initrd-rt.img", "digest")), + vec![], + vec![], + ) + .expect("valid manifest with initrd"); + + assert_eq!( + compare(&without_initrd, &with_initrd).differences(), + &[SemanticDifference::Initrd { + change: Change::Added + }] + ); + assert_eq!( + compare(&with_initrd, &without_initrd).differences(), + &[SemanticDifference::Initrd { + change: Change::Removed + }] + ); +} + +#[test] fn reads_and_writes_a_toml_manifest_beside_an_artifact() { let fixture = tempdir().expect("temporary directory"); let artifact = fixture.path().join("controller.tar"); |