From 308fa8dbb86db5610f84ac9230266ba067a23184 Mon Sep 17 00:00:00 2001 From: Thomas Eppers Date: Fri, 17 Feb 2023 13:23:08 +0100 Subject: [PATCH] fixed tests --- src/repo.rs | 89 +++++++++++++++++++++++++++++------------------------ 1 file changed, 49 insertions(+), 40 deletions(-) diff --git a/src/repo.rs b/src/repo.rs index 25565d1..4bd22a6 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -87,80 +87,89 @@ mod tests { use crate::repo::{Error, Repo}; #[test] - fn test_split_repo_without_tag() { - let input: Vec<(&str, Result)> = vec![ - ("", Err(Error::MisformedInput)), - ("NGINX", Err(Error::MisformedInput)), - ("nginx", Ok(Repo::Project("nginx".into()))), + fn test_split_repo_without_tag_error() { + let input: Vec<&str> = vec!["", "NGINX"]; + for i in input { + assert!(super::split_repo_without_tag(i).is_err()); + } + } + + #[test] + fn test_split_repo_without_tag() -> Result<(), Error> { + let input: Vec<(&str, Repo)> = vec![ + ("nginx", Repo::Project("nginx".into())), ( "library/nginx", - Ok(Repo::WithOrga("library".into(), "nginx".into())), + Repo::WithOrga("library".into(), "nginx".into()), ), ( "ghcr.io/library/nginx", - Ok(Repo::WithServer( - "ghcr.io".into(), - "library".into(), - "nginx".into(), - )), + Repo::WithServer("ghcr.io".into(), "library".into(), "nginx".into()), ), ( "te-st/test-hypen", - Ok(Repo::WithOrga("te-st".into(), "test-hypen".into())), + Repo::WithOrga("te-st".into(), "test-hypen".into()), ), ( "test/test.dot", - Ok(Repo::WithOrga("test".into(), "test.dot".into())), + Repo::WithOrga("test".into(), "test.dot".into()), ), ]; 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] - fn test_match_yaml_image() { - let input: Vec<(&str, Result<(&str, &str), Error>)> = vec![ - ("", Err(Error::NoTagFound)), - ("version: '2'", Err(Error::NoTagFound)), - ("image: ", Err(Error::NoTagFound)), - (" image: ", Err(Error::NoTagFound)), - (" image: nginx", Ok((" image: ", "nginx"))), - (" image: library/nginx", Ok((" image: ", "library/nginx"))), + fn test_match_yaml_image() -> Result<(), Error> { + let input: Vec<(&str, (&str, &str))> = vec![ + (" image: nginx", (" image: ", "nginx")), + (" image: library/nginx", (" image: ", "library/nginx")), ( - " image: gchr.io/library/nginx", - Ok((" image: ", "gchr.io/library/nginx")), + " image: ghcr.io/library/nginx", + (" image: ", "ghcr.io/library/nginx"), ), - (" image: nginx # comment", Ok((" image: ", "nginx"))), - (" image: test-hyphen", Ok((" image: ", "test-hyphen"))), - (" image: test.dot", Ok((" image: ", "test.dot"))), + (" image: nginx # comment", (" image: ", "nginx")), + (" image: test-hyphen", (" image: ", "test-hyphen")), + (" image: test.dot", (" image: ", "test.dot")), ]; 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] - fn test_split_tag_from_repo() { - let input: Vec<(&str, Result<(&str, &str), super::Error>)> = vec![ - ("nginx", Ok(("nginx", ""))), - ("library/nginx", Ok(("library/nginx", ""))), - ("ghcr.io/library/nginx", Ok(("ghcr.io/library/nginx", ""))), - ("nginx:", Ok(("nginx", ""))), - ("nginx:1", Ok(("nginx", "1"))), - ("nginx:latest", Ok(("nginx", "latest"))), - ("hy-phen:latest", Ok(("hy-phen", "latest"))), - ("test.dot:latest", Ok(("test.dot", "latest"))), + fn test_split_tag_from_repo() -> Result<(), Error> { + let input: Vec<(&str, (&str, &str))> = vec![ + ("nginx", ("nginx", "")), + ("library/nginx", ("library/nginx", "")), + ("ghcr.io/library/nginx", ("ghcr.io/library/nginx", "")), + ("nginx:", ("nginx", "")), + ("nginx:1", ("nginx", "1")), + ("nginx:latest", ("nginx", "latest")), + ("hy-phen:latest", ("hy-phen", "latest")), + ("test.dot:latest", ("test.dot", "latest")), ( "woodpeckerci/woodpecker-server", - Ok(("woodpeckerci/woodpecker-server", "")), + ("woodpeckerci/woodpecker-server", ""), ), ]; 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(()) } }