Skip to content

Commit

Permalink
spec: impl Display for ImageReference
Browse files Browse the repository at this point in the history
I want this in a followup patch.

Signed-off-by: Colin Walters <[email protected]>
  • Loading branch information
cgwalters committed Jan 16, 2024
1 parent b075e03 commit 877af96
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/src/spec.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//! The definition for host system state.
use std::fmt::Display;

use ostree_ext::container::OstreeImageReference;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -149,8 +152,17 @@ impl Default for Host {
}
}

impl Display for ImageReference {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let ostree_imgref = OstreeImageReference::from(self.clone());
ostree_imgref.fmt(f)
}
}

#[cfg(test)]
mod tests {
use std::str::FromStr;

use super::*;

#[test]
Expand Down Expand Up @@ -183,4 +195,13 @@ mod tests {
Some(ImageSignature::OstreeRemote("fedora".into()))
);
}

#[test]
fn test_display_imgref() {
let src = "ostree-unverified-registry:quay.io/example/foo:sometag";
let s = OstreeImageReference::from_str(src).unwrap();
let s = ImageReference::from(s);
let displayed = format!("{s}");
assert_eq!(displayed.as_str(), src);
}
}

0 comments on commit 877af96

Please sign in to comment.