fixed tests

This commit is contained in:
Thomas Eppers 2023-02-17 13:23:08 +01:00
parent cd0479a618
commit 308fa8dbb8

View File

@ -87,80 +87,89 @@ mod tests {
use crate::repo::{Error, Repo}; use crate::repo::{Error, Repo};
#[test] #[test]
fn test_split_repo_without_tag() { fn test_split_repo_without_tag_error() {
let input: Vec<(&str, Result<Repo, Error>)> = vec![ let input: Vec<&str> = vec!["", "NGINX"];
("", Err(Error::MisformedInput)), for i in input {
("NGINX", Err(Error::MisformedInput)), assert!(super::split_repo_without_tag(i).is_err());
("nginx", Ok(Repo::Project("nginx".into()))), }
}
#[test]
fn test_split_repo_without_tag() -> Result<(), Error> {
let input: Vec<(&str, Repo)> = vec![
("nginx", Repo::Project("nginx".into())),
( (
"library/nginx", "library/nginx",
Ok(Repo::WithOrga("library".into(), "nginx".into())), Repo::WithOrga("library".into(), "nginx".into()),
), ),
( (
"ghcr.io/library/nginx", "ghcr.io/library/nginx",
Ok(Repo::WithServer( Repo::WithServer("ghcr.io".into(), "library".into(), "nginx".into()),
"ghcr.io".into(),
"library".into(),
"nginx".into(),
)),
), ),
( (
"te-st/test-hypen", "te-st/test-hypen",
Ok(Repo::WithOrga("te-st".into(), "test-hypen".into())), Repo::WithOrga("te-st".into(), "test-hypen".into()),
), ),
( (
"test/test.dot", "test/test.dot",
Ok(Repo::WithOrga("test".into(), "test.dot".into())), Repo::WithOrga("test".into(), "test.dot".into()),
), ),
]; ];
for i in input { for i in input {
assert_eq!(super::split_repo_without_tag(i.0), i.1); assert_eq!(super::split_repo_without_tag(i.0)?, i.1);
}
Ok(())
}
#[test]
fn test_match_yaml_image_error() {
let input: Vec<&str> = vec!["", "version: '2'", "image: ", " image: "];
for i in input {
assert!(super::match_yaml_image(i).is_err());
} }
} }
#[test] #[test]
fn test_match_yaml_image() { fn test_match_yaml_image() -> Result<(), Error> {
let input: Vec<(&str, Result<(&str, &str), Error>)> = vec![ let input: Vec<(&str, (&str, &str))> = vec![
("", Err(Error::NoTagFound)), (" image: nginx", (" image: ", "nginx")),
("version: '2'", Err(Error::NoTagFound)), (" image: library/nginx", (" image: ", "library/nginx")),
("image: ", Err(Error::NoTagFound)),
(" image: ", Err(Error::NoTagFound)),
(" image: nginx", Ok((" image: ", "nginx"))),
(" image: library/nginx", Ok((" image: ", "library/nginx"))),
( (
" image: gchr.io/library/nginx", " image: ghcr.io/library/nginx",
Ok((" image: ", "gchr.io/library/nginx")), (" image: ", "ghcr.io/library/nginx"),
), ),
(" image: nginx # comment", Ok((" image: ", "nginx"))), (" image: nginx # comment", (" image: ", "nginx")),
(" image: test-hyphen", Ok((" image: ", "test-hyphen"))), (" image: test-hyphen", (" image: ", "test-hyphen")),
(" image: test.dot", Ok((" image: ", "test.dot"))), (" image: test.dot", (" image: ", "test.dot")),
]; ];
for i in input { for i in input {
assert_eq!(super::match_yaml_image(i.0), i.1); assert_eq!(super::match_yaml_image(i.0)?, i.1);
} }
Ok(())
} }
#[test] #[test]
fn test_split_tag_from_repo() { fn test_split_tag_from_repo() -> Result<(), Error> {
let input: Vec<(&str, Result<(&str, &str), super::Error>)> = vec![ let input: Vec<(&str, (&str, &str))> = vec![
("nginx", Ok(("nginx", ""))), ("nginx", ("nginx", "")),
("library/nginx", Ok(("library/nginx", ""))), ("library/nginx", ("library/nginx", "")),
("ghcr.io/library/nginx", Ok(("ghcr.io/library/nginx", ""))), ("ghcr.io/library/nginx", ("ghcr.io/library/nginx", "")),
("nginx:", Ok(("nginx", ""))), ("nginx:", ("nginx", "")),
("nginx:1", Ok(("nginx", "1"))), ("nginx:1", ("nginx", "1")),
("nginx:latest", Ok(("nginx", "latest"))), ("nginx:latest", ("nginx", "latest")),
("hy-phen:latest", Ok(("hy-phen", "latest"))), ("hy-phen:latest", ("hy-phen", "latest")),
("test.dot:latest", Ok(("test.dot", "latest"))), ("test.dot:latest", ("test.dot", "latest")),
( (
"woodpeckerci/woodpecker-server", "woodpeckerci/woodpecker-server",
Ok(("woodpeckerci/woodpecker-server", "")), ("woodpeckerci/woodpecker-server", ""),
), ),
]; ];
for i in input { for i in input {
assert_eq!(super::split_tag_from_repo(i.0), i.1); assert_eq!(super::split_tag_from_repo(i.0)?, i.1);
} }
Ok(())
} }
} }