Skip to content

Commit

Permalink
Merge pull request #56 from exdx/fix/digest-image-parsing
Browse files Browse the repository at this point in the history
fix: Parse image tag for digest-based images
  • Loading branch information
exdx authored Sep 4, 2022
2 parents 5217d39 + cec7371 commit 1c2b90b
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ pub struct Image {

impl Image {
pub fn split(&self) -> Option<(String, String)> {
let image_split: Vec<&str> = self.image.split(':').collect();
let image_split: Vec<&str> = if self.image.contains('@') {
self.image.split('@').collect()
} else {
self.image.split(':').collect()
};

if image_split.is_empty() {
return None;
}
Expand Down Expand Up @@ -72,3 +77,23 @@ pub async fn is_present_locally_podman(images: PodmanImages, search_for_image: S
}
false
}

#[cfg(test)]
mod tests {
use super::Image;

#[test]
fn test_split() {
let digest_image = "quay.io/tflannag/bundles@sha256:145ccb5e7e73d4ae914160c066e49f35bc2be2bb86e4ab0002a802aa436599bf";
let image = Image {
image: digest_image.to_string(),
};

let (out_repo, out_tag) = image.split().unwrap();
assert_eq!(out_repo, "quay.io/tflannag/bundles".to_string());
assert_eq!(
out_tag,
"sha256:145ccb5e7e73d4ae914160c066e49f35bc2be2bb86e4ab0002a802aa436599bf".to_string()
);
}
}

0 comments on commit 1c2b90b

Please sign in to comment.