diff --git a/lib/src/rhsm.rs b/lib/src/rhsm.rs index 81e76b50..2bb94780 100644 --- a/lib/src/rhsm.rs +++ b/lib/src/rhsm.rs @@ -8,7 +8,7 @@ use serde::Serialize; const FACTS_PATH: &str = "etc/rhsm/facts/bootc.json"; -#[derive(Serialize)] +#[derive(Serialize, PartialEq, Debug, Default)] struct RhsmFacts { #[serde(rename = "bootc.booted.image")] booted_image: String, @@ -47,7 +47,7 @@ impl From for RhsmFacts { let version = imagestatus.version.as_ref().cloned().unwrap_or_default(); let digest = imagestatus.image_digest.clone(); - (image, digest, version) + (image, version, digest) }) }) .unwrap_or_default(); @@ -61,7 +61,7 @@ impl From for RhsmFacts { let version = imagestatus.version.as_ref().cloned().unwrap_or_default(); let digest = imagestatus.image_digest.clone(); - (image, digest, version) + (image, version, digest) }) }) .unwrap_or_default(); @@ -75,7 +75,7 @@ impl From for RhsmFacts { let version = imagestatus.version.as_ref().cloned().unwrap_or_default(); let digest = imagestatus.image_digest.clone(); - (image, digest, version) + (image, version, digest) }) }) .unwrap_or_default(); @@ -89,7 +89,7 @@ impl From for RhsmFacts { let version = imagestatus.version.as_ref().cloned().unwrap_or_default(); let digest = imagestatus.image_digest.clone(); - (image, digest, version) + (image, version, digest) }) }) .unwrap_or_default(); @@ -126,3 +126,32 @@ pub(crate) async fn publish_facts(root: &Dir) -> Result<()> { serde_json::to_writer_pretty(&mut bootc_facts_file, &facts)?; Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + use crate::spec::Host; + + #[test] + fn test_rhsm_facts_from_host() { + let host: Host = serde_yaml::from_str(include_str!("fixtures/spec-staged-booted.yaml")) + .expect("No spec found"); + let facts = RhsmFacts::from(host.status); + + assert_eq!( + facts, + RhsmFacts { + booted_image: "quay.io/example/someimage:latest".into(), + booted_version: "nightly".into(), + booted_digest: + "sha256:736b359467c9437c1ac915acaae952aad854e07eb4a16a94999a48af08c83c34".into(), + staged_image: "quay.io/example/someimage:latest".into(), + staged_version: "nightly".into(), + staged_digest: + "sha256:16dc2b6256b4ff0d2ec18d2dbfb06d117904010c8cf9732cdb022818cf7a7566".into(), + ..Default::default() + } + ); + } +}