mirror of
https://github.com/sergi0g/cup.git
synced 2025-11-17 09:33:38 -05:00
Test split
This commit is contained in:
@@ -5,7 +5,7 @@ use regex::Regex;
|
|||||||
|
|
||||||
use super::status::Status;
|
use super::status::Status;
|
||||||
|
|
||||||
/// Heavily modified version of the official semver regex based on common tagging schemes for container images. Sometimes it matches more than once, but we'll try to select the best match. Yes, there _will_ be errors.
|
/// Heavily modified version of the official semver regex based on common tagging schemes for container images. Sometimes it matches more than once, but we'll try to select the best match.
|
||||||
static SEMVER_REGEX: Lazy<Regex> = Lazy::new(|| {
|
static SEMVER_REGEX: Lazy<Regex> = Lazy::new(|| {
|
||||||
Regex::new(r#"(?P<major>0|[1-9]\d*)(?:\.(?P<minor>0|[1-9]\d*))?(?:\.(?P<patch>0|[1-9]\d*)+)?"#)
|
Regex::new(r#"(?P<major>0|[1-9]\d*)(?:\.(?P<minor>0|[1-9]\d*))?(?:\.(?P<patch>0|[1-9]\d*)+)?"#)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@@ -20,7 +20,7 @@ pub struct Version {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Version {
|
impl Version {
|
||||||
/// Tries to parse the tag into semver-like parts. Should have been included in impl Image, but that would make the tests more complicated
|
/// Tries to parse the tag into semver-like parts.
|
||||||
pub fn from_tag(tag: &str) -> Option<Self> {
|
pub fn from_tag(tag: &str) -> Option<Self> {
|
||||||
let captures = SEMVER_REGEX.captures_iter(tag);
|
let captures = SEMVER_REGEX.captures_iter(tag);
|
||||||
// And now... terrible best match selection for everyone!
|
// And now... terrible best match selection for everyone!
|
||||||
|
|||||||
@@ -44,3 +44,25 @@ static REFERENCE_REGEX: Lazy<Regex> = Lazy::new(|| {
|
|||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[rustfmt::skip]
|
||||||
|
fn reference() {
|
||||||
|
assert_eq!(split("alpine"), (String::from(DEFAULT_REGISTRY), String::from("library/alpine"), String::from("latest")));
|
||||||
|
assert_eq!(split("alpine:latest"), (String::from(DEFAULT_REGISTRY), String::from("library/alpine"), String::from("latest")));
|
||||||
|
assert_eq!(split("library/alpine"), (String::from(DEFAULT_REGISTRY), String::from("library/alpine"), String::from("latest")));
|
||||||
|
assert_eq!(split("localhost/test"), (String::from("localhost"), String::from("test"), String::from("latest")));
|
||||||
|
assert_eq!(split("localhost:1234/test"), (String::from("localhost:1234"), String::from("test"), String::from("latest")));
|
||||||
|
assert_eq!(split("test:1234/idk"), (String::from("test:1234"), String::from("idk"), String::from("latest")));
|
||||||
|
assert_eq!(split("alpine:3.7"), (String::from(DEFAULT_REGISTRY), String::from("library/alpine"), String::from("3.7")));
|
||||||
|
assert_eq!(split("docker.example.com/examplerepo/alpine:3.7"), (String::from("docker.example.com"), String::from("examplerepo/alpine"), String::from("3.7")));
|
||||||
|
assert_eq!(split("docker.example.com/examplerepo/alpine/test2:3.7"), (String::from("docker.example.com"), String::from("examplerepo/alpine/test2"), String::from("3.7")));
|
||||||
|
assert_eq!(split("docker.example.com/examplerepo/alpine/test2/test3:3.7"), (String::from("docker.example.com"), String::from("examplerepo/alpine/test2/test3"), String::from("3.7")));
|
||||||
|
assert_eq!(split("docker.example.com:5000/examplerepo/alpine:latest"), (String::from("docker.example.com:5000"), String::from("examplerepo/alpine"), String::from("latest")));
|
||||||
|
assert_eq!(split("portainer/portainer:latest"), (String::from(DEFAULT_REGISTRY), String::from("portainer/portainer"), String::from("latest")));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user