fixed tests
This commit is contained in:
parent
cd0479a618
commit
308fa8dbb8
91
src/repo.rs
91
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<Repo, Error>)> = 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(())
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user