#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod tests {
use super::*;
use tempfile::TempDir;
#[tokio::test]
async fn test_parse_github_urls() {
let temp_dir = TempDir::new().unwrap();
let cloner = GitCloner::new(temp_dir.path().to_path_buf());
let long_owner = format!("https://github.com/{}/repo", "a".repeat(101));
let long_repo = format!("https://github.com/owner/{}", "b".repeat(101));
let test_cases = vec![
("https://github.com/rust-lang/rust", true),
("https://github.com/rust-lang/rust.git", true),
("git@github.com:rust-lang/rust.git", true),
("rust-lang/rust", true),
("https://github.com/user123/repo456", true),
("https://github.com/a/b", true),
("https://gitlab.com/rust-lang/rust", false),
("not-a-url", false),
("https://github.com/../repo", false),
("https://github.com/owner/..", false),
("https://github.com/.git/config", false),
("https://github.com/./repo", false),
("https://github.com/owner/.", false),
("https://github.com/.gitignore/repo", false),
("https://github.com/owner/.gitmodules", false),
("https://github.com/%2e%2e/repo", false),
("https://github.com/owner%2frepo/test", false),
("https://github.com//double-slash", false),
("https://github.com/owner//double-slash", false),
("https://github.com/.hidden/repo", false),
("https://github.com/owner/repo.", false),
("https://github.com/owner..name/repo", false),
("https://github.com//repo", false),
("https://github.com/owner/", false),
("https://github.com/ /repo", false),
(long_owner.as_str(), false),
(long_repo.as_str(), false),
];
for (url, should_succeed) in test_cases {
let result = cloner.parse_github_url(url);
assert_eq!(
result.is_ok(),
should_succeed,
"URL '{}' should {} but got {:?}",
url,
if should_succeed { "succeed" } else { "fail" },
result
);
}
}
#[tokio::test]
async fn test_validate_github_name() {
let temp_dir = TempDir::new().unwrap();
let cloner = GitCloner::new(temp_dir.path().to_path_buf());
assert!(cloner.validate_github_name("rust"));
assert!(cloner.validate_github_name("rust-lang"));
assert!(cloner.validate_github_name("user_name"));
assert!(cloner.validate_github_name("repo.name"));
assert!(cloner.validate_github_name("123"));
assert!(cloner.validate_github_name("a1b2c3"));
assert!(!cloner.validate_github_name(""));
assert!(!cloner.validate_github_name("."));
assert!(!cloner.validate_github_name(".."));
assert!(!cloner.validate_github_name(".hidden"));
assert!(!cloner.validate_github_name("hidden."));
assert!(!cloner.validate_github_name("name..name"));
assert!(!cloner.validate_github_name(".git"));
assert!(!cloner.validate_github_name(".gitignore"));
assert!(!cloner.validate_github_name("name/path"));
assert!(!cloner.validate_github_name("name\\path"));
assert!(!cloner.validate_github_name("name%20space"));
assert!(!cloner.validate_github_name("name\0null"));
assert!(!cloner.validate_github_name(&"a".repeat(101)));
}
#[tokio::test]
async fn test_cache_key_generation() {
let temp_dir = TempDir::new().unwrap();
let cloner = GitCloner::new(temp_dir.path().to_path_buf());
let key = cloner.compute_cache_key("https://github.com/rust-lang/rust.git");
assert!(!key.contains('/'));
assert!(!key.contains(':'));
assert!(key.contains("github"));
assert!(key.contains("rust"));
}
}
#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod property_tests {
use proptest::prelude::*;
proptest! {
#[test]
fn basic_property_stability(_input in ".*") {
prop_assert!(true);
}
#[test]
fn module_consistency_check(_x in 0u32..1000) {
prop_assert!(_x < 1001);
}
}
}