Merge tag 'v1.2.1' into development
This commit is contained in:
commit
13350f872a
113
src/repo.rs
113
src/repo.rs
@ -30,7 +30,7 @@ pub enum Repo {
|
|||||||
/// the second &str will the the identifier for the image
|
/// the second &str will the the identifier for the image
|
||||||
pub fn match_yaml_image(input: &str) -> Result<(&str, &str), Error> {
|
pub fn match_yaml_image(input: &str) -> Result<(&str, &str), Error> {
|
||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
static ref REGEX: Regex = Regex::new(r"^( +image *: *)([a-z0-9\./:]+)").unwrap();
|
static ref REGEX: Regex = Regex::new(r"^( +image *: *)([a-z0-9\-\./:]+)").unwrap();
|
||||||
}
|
}
|
||||||
let caps = match REGEX.captures(input) {
|
let caps = match REGEX.captures(input) {
|
||||||
Some(caps) => caps,
|
Some(caps) => caps,
|
||||||
@ -103,58 +103,79 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_split_repo_without_tag() {
|
fn test_split_repo_without_tag() {
|
||||||
use crate::repo::split_repo_without_tag as test_fn;
|
let input: Vec<(&str, Result<Repo, Error>)> = vec![
|
||||||
assert_eq!(test_fn(""), Err(Error::MisformedInput));
|
("", Err(Error::MisformedInput)),
|
||||||
assert_eq!(test_fn("NGINX"), Err(Error::MisformedInput));
|
("NGINX", Err(Error::MisformedInput)),
|
||||||
assert_eq!(test_fn("nginx"), Ok(Repo::Project("nginx".into())));
|
("nginx", Ok(Repo::Project("nginx".into()))),
|
||||||
assert_eq!(
|
(
|
||||||
test_fn("library/nginx"),
|
"library/nginx",
|
||||||
Ok(Repo::WithOrga("library".into(), "nginx".into()))
|
Ok(Repo::WithOrga("library".into(), "nginx".into())),
|
||||||
);
|
),
|
||||||
assert_eq!(
|
(
|
||||||
test_fn("ghcr.io/library/nginx"),
|
"ghcr.io/library/nginx",
|
||||||
Ok(Repo::WithServer(
|
Ok(Repo::WithServer(
|
||||||
"ghcr.io".into(),
|
"ghcr.io".into(),
|
||||||
"library".into(),
|
"library".into(),
|
||||||
"nginx".into(),
|
"nginx".into(),
|
||||||
))
|
)),
|
||||||
);
|
),
|
||||||
|
(
|
||||||
|
"te-st/test-hypen",
|
||||||
|
Ok(Repo::WithOrga("te-st".into(), "test-hypen".into())),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"test/test.dot",
|
||||||
|
Ok(Repo::WithOrga("test".into(), "test.dot".into())),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
for i in input {
|
||||||
|
assert_eq!(super::split_repo_without_tag(i.0), i.1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_match_yaml_image() {
|
fn test_match_yaml_image() {
|
||||||
use crate::repo::match_yaml_image as test_fn;
|
let input: Vec<(&str, Result<(&str, &str), Error>)> = vec![
|
||||||
assert_eq!(test_fn(""), Err(Error::NoTagFound));
|
("", Err(Error::NoTagFound)),
|
||||||
assert_eq!(test_fn("version: '2'"), Err(Error::NoTagFound));
|
("version: '2'", Err(Error::NoTagFound)),
|
||||||
assert_eq!(test_fn("image: "), Err(Error::NoTagFound));
|
("image: ", Err(Error::NoTagFound)),
|
||||||
assert_eq!(test_fn(" image: "), Err(Error::NoTagFound));
|
(" image: ", Err(Error::NoTagFound)),
|
||||||
assert_eq!(test_fn(" image: nginx"), Ok((" image: ", "nginx")));
|
(" image: nginx", Ok((" image: ", "nginx"))),
|
||||||
assert_eq!(
|
(" image: library/nginx", Ok((" image: ", "library/nginx"))),
|
||||||
test_fn(" image: library/nginx"),
|
(
|
||||||
Ok((" image: ", "library/nginx"))
|
" image: gchr.io/library/nginx",
|
||||||
);
|
Ok((" image: ", "gchr.io/library/nginx")),
|
||||||
assert_eq!(
|
),
|
||||||
test_fn(" image: ghcr.io/library/nginx"),
|
(" image: nginx # comment", Ok((" image: ", "nginx"))),
|
||||||
Ok((" image: ", "ghcr.io/library/nginx"))
|
(" image: test-hyphen", Ok((" image: ", "test-hyphen"))),
|
||||||
);
|
(" image: test.dot", Ok((" image: ", "test.dot"))),
|
||||||
assert_eq!(test_fn("# image: nginx"), Err(Error::NoTagFound));
|
];
|
||||||
assert_eq!(
|
|
||||||
test_fn(" image: nginx #comment"),
|
for i in input {
|
||||||
Ok((" image: ", "nginx"))
|
assert_eq!(super::match_yaml_image(i.0), i.1);
|
||||||
);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_split_tag_from_repo() {
|
fn test_split_tag_from_repo() {
|
||||||
use crate::repo::split_tag_from_repo as test_fn;
|
let input: Vec<(&str, Result<(&str, &str), super::Error>)> = vec![
|
||||||
assert_eq!(test_fn("nginx"), Ok(("nginx", "")));
|
("nginx", Ok(("nginx", ""))),
|
||||||
assert_eq!(test_fn("library/nginx"), Ok(("library/nginx", "")));
|
("library/nginx", Ok(("library/nginx", ""))),
|
||||||
assert_eq!(
|
("ghcr.io/library/nginx", Ok(("ghcr.io/library/nginx", ""))),
|
||||||
test_fn("ghcr.io/library/nginx"),
|
("nginx:", Ok(("nginx", ""))),
|
||||||
Ok(("ghcr.io/library/nginx", ""))
|
("nginx:1", Ok(("nginx", "1"))),
|
||||||
);
|
("nginx:latest", Ok(("nginx", "latest"))),
|
||||||
assert_eq!(test_fn("nginx:"), Ok(("nginx", "")));
|
("hy-phen:latest", Ok(("hy-phen", "latest"))),
|
||||||
assert_eq!(test_fn("nginx:1"), Ok(("nginx", "1")));
|
("test.dot:latest", Ok(("test.dot", "latest"))),
|
||||||
assert_eq!(test_fn("nginx:latest"), Ok(("nginx", "latest")));
|
(
|
||||||
|
"woodpeckerci/woodpecker-server",
|
||||||
|
Ok(("woodpeckerci/woodpecker-server", "")),
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
for i in input {
|
||||||
|
assert_eq!(super::split_tag_from_repo(i.0), i.1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user