Skip to content

Commit

Permalink
fixup! Add "rhsm" feature for integration with Red Hat Subscription M…
Browse files Browse the repository at this point in the history
…anager
  • Loading branch information
jeckersb committed Dec 18, 2024
1 parent 1bf188b commit db0a07a
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions lib/src/rhsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -47,7 +47,7 @@ impl From<crate::spec::HostStatus> 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();
Expand All @@ -61,7 +61,7 @@ impl From<crate::spec::HostStatus> 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();
Expand All @@ -75,7 +75,7 @@ impl From<crate::spec::HostStatus> 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();
Expand All @@ -89,7 +89,7 @@ impl From<crate::spec::HostStatus> 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();
Expand Down Expand Up @@ -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()
}
);
}
}

0 comments on commit db0a07a

Please sign in to comment.