Added tests for ImageIdentifier

This commit is contained in:
strNophix 2022-06-26 12:08:51 +02:00
parent 27c8932a05
commit cad83660e9

View File

@ -71,6 +71,7 @@ impl Registry {
}
}
#[derive(Debug, PartialEq)]
pub struct ImageIdentifier {
author: String,
name: String,
@ -90,3 +91,47 @@ impl ImageIdentifier {
return ImageIdentifier { author, name, tag };
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_parse_image_name() {
assert_eq!(
ImageIdentifier::from_string(&"library/ubuntu:latest".to_string()),
ImageIdentifier {
author: "library".to_string(),
name: "ubuntu".to_string(),
tag: "latest".to_string()
}
);
assert_eq!(
ImageIdentifier::from_string(&"alpine".to_string()),
ImageIdentifier {
author: "library".to_string(),
name: "alpine".to_string(),
tag: "latest".to_string()
}
);
assert_eq!(
ImageIdentifier::from_string(&"ghcr.io/dusk-labs/dim:dev".to_string()),
ImageIdentifier {
author: "dusk-labs".to_string(),
name: "dim".to_string(),
tag: "dev".to_string()
}
);
assert_eq!(
ImageIdentifier::from_string(&"bitnami/redis:7.0".to_string()),
ImageIdentifier {
author: "bitnami".to_string(),
name: "redis".to_string(),
tag: "7.0".to_string()
}
);
}
}