use nyl::git::argocd::{matches_repo_creds_pattern, matches_repository_url};
#[test]
fn test_matches_repository_url_exact() {
assert!(matches_repository_url(
"https://github.com/org/repo",
"https://github.com/org/repo"
));
assert!(matches_repository_url(
"https://github.com/org/repo.git",
"https://github.com/org/repo"
));
assert!(matches_repository_url(
"https://github.com/org/repo.git",
"https://github.com/org/repo.git"
));
}
#[test]
fn test_matches_repository_url_ssh_shorthand() {
assert!(matches_repository_url(
"git@github.com:org/repo",
"ssh://git@github.com/org/repo"
));
assert!(matches_repository_url(
"git@github.com:org/repo",
"git@github.com:org/repo"
));
assert!(matches_repository_url(
"git@github.com:org/repo.git",
"git@github.com:org/repo"
));
}
#[test]
fn test_matches_repository_url_hostname_fallback() {
assert!(matches_repository_url(
"https://github.com/org/repo1",
"https://github.com/org/repo2"
));
assert!(!matches_repository_url(
"https://github.com/org/repo",
"https://gitlab.com/org/repo"
));
}
#[test]
fn test_matches_repository_url_mixed_protocols() {
assert!(matches_repository_url(
"https://github.com/org/repo",
"git@github.com:org/repo"
));
assert!(matches_repository_url(
"git@github.com:org/repo",
"https://github.com/org/repo"
));
}
#[test]
fn test_matches_repository_url_case_insensitive() {
assert!(matches_repository_url(
"https://GitHub.com/org/repo",
"https://github.com/org/repo"
));
assert!(matches_repository_url(
"https://GitHub.com/Org/Repo",
"https://github.com/org/repo"
));
}
#[test]
fn test_matches_repository_url_trailing_slash() {
assert!(matches_repository_url(
"https://github.com/org/repo/",
"https://github.com/org/repo"
));
assert!(matches_repository_url(
"https://github.com/org/repo/",
"https://github.com/org/repo/"
));
}
#[test]
fn test_matches_repository_url_different_providers() {
assert!(!matches_repository_url(
"https://github.com/org/repo",
"https://gitlab.com/org/repo"
));
assert!(!matches_repository_url(
"https://github.com/org/repo",
"https://gitea.example.com/org/repo"
));
}
#[test]
fn test_matches_repository_url_subpaths() {
assert!(matches_repository_url(
"https://github.com/org1/repo1",
"https://github.com/org2/repo2"
));
assert!(matches_repository_url(
"https://github.com/org/repo1",
"https://github.com/org/repo2"
));
}
#[test]
fn test_matches_repo_creds_pattern_simple_wildcard() {
assert!(matches_repo_creds_pattern(
"https://github.com/myorg/*",
"https://github.com/myorg/repo1"
));
assert!(matches_repo_creds_pattern(
"https://github.com/myorg/*",
"https://github.com/myorg/charts"
));
assert!(!matches_repo_creds_pattern(
"https://github.com/myorg/*",
"https://github.com/otherorg/repo"
));
}
#[test]
fn test_matches_repo_creds_pattern_broader_wildcard() {
assert!(matches_repo_creds_pattern(
"https://github.com/*",
"https://github.com/anyorg/anyrepo"
));
assert!(matches_repo_creds_pattern(
"https://github.com/*",
"https://github.com/myorg/charts"
));
assert!(!matches_repo_creds_pattern(
"https://github.com/*",
"https://gitlab.com/org/repo"
));
}
#[test]
fn test_matches_repo_creds_pattern_ssh_shorthand() {
assert!(matches_repo_creds_pattern(
"git@github.com:myorg/*",
"git@github.com:myorg/charts"
));
assert!(matches_repo_creds_pattern(
"git@github.com:myorg/*",
"ssh://git@github.com/myorg/charts"
));
assert!(!matches_repo_creds_pattern(
"git@github.com:myorg/*",
"git@github.com:otherorg/repo"
));
}
#[test]
fn test_matches_repo_creds_pattern_with_git_suffix() {
assert!(matches_repo_creds_pattern(
"https://github.com/myorg/*.git",
"https://github.com/myorg/repo.git"
));
assert!(matches_repo_creds_pattern(
"https://github.com/myorg/*",
"https://github.com/myorg/repo.git"
));
assert!(matches_repo_creds_pattern(
"https://github.com/myorg/*.git",
"https://github.com/myorg/repo"
));
}
#[test]
fn test_matches_repo_creds_pattern_case_insensitive() {
assert!(matches_repo_creds_pattern(
"https://GitHub.com/MyOrg/*",
"https://github.com/myorg/repo"
));
assert!(matches_repo_creds_pattern(
"https://github.com/myorg/*",
"https://GitHub.com/MyOrg/Repo"
));
}
#[test]
fn test_matches_repo_creds_pattern_multiple_levels() {
assert!(matches_repo_creds_pattern(
"https://gitlab.com/*/*",
"https://gitlab.com/group/project"
));
assert!(matches_repo_creds_pattern(
"https://gitlab.com/mygroup/*",
"https://gitlab.com/mygroup/subgroup/project"
));
}
#[test]
fn test_matches_repo_creds_pattern_exact_vs_pattern() {
assert!(!matches_repo_creds_pattern(
"https://github.com/myorg/specific-repo",
"https://github.com/myorg/other-repo"
));
assert!(matches_repo_creds_pattern(
"https://github.com/myorg/repo",
"https://github.com/myorg/repo"
));
}
#[test]
fn test_matches_repo_creds_pattern_trailing_slash() {
assert!(matches_repo_creds_pattern(
"https://github.com/myorg/*/",
"https://github.com/myorg/repo"
));
assert!(matches_repo_creds_pattern(
"https://github.com/myorg/*",
"https://github.com/myorg/repo/"
));
}
#[test]
fn test_matches_repo_creds_pattern_special_chars() {
assert!(matches_repo_creds_pattern(
"https://git.example.com/my-org/*",
"https://git.example.com/my-org/my-repo"
));
assert!(!matches_repo_creds_pattern(
"https://git.example.com/*",
"https://gitXexampleXcom/org/repo"
));
}
#[test]
fn test_precedence_exact_beats_pattern() {
let exact_url = "https://github.com/myorg/charts";
let pattern = "https://github.com/myorg/*";
assert!(matches_repository_url(exact_url, exact_url));
assert!(matches_repo_creds_pattern(pattern, exact_url));
}
#[test]
fn test_precedence_pattern_beats_hostname() {
let url = "https://github.com/myorg/repo1";
let pattern = "https://github.com/myorg/*";
let different_repo = "https://github.com/otherorg/repo2";
assert!(matches_repo_creds_pattern(pattern, url));
assert!(matches_repository_url(different_repo, url));
}
#[test]
fn test_no_match_different_providers() {
assert!(!matches_repo_creds_pattern(
"https://github.com/*",
"https://gitlab.com/org/repo"
));
assert!(!matches_repo_creds_pattern(
"git@github.com:*/*",
"git@gitlab.com:org/repo"
));
}