#[test]
fn test_try_local_path_exists() {
let temp_dir = TempDir::new().unwrap();
let path_str = temp_dir.path().to_string_lossy().to_string();
let result = try_local_path(&path_str);
assert!(result.is_some());
assert!(result.unwrap().is_err());
}
#[test]
fn test_try_local_path_not_exists() {
let result = try_local_path("/nonexistent/path/that/doesnt/exist/at/all");
assert!(result.is_none());
}
#[test]
fn test_try_github_shorthand() {
let result = try_github_shorthand("gh:owner/repo");
assert!(result.is_some());
let path = result.unwrap().unwrap();
assert!(path.to_string_lossy().contains("github.com"));
assert!(path.to_string_lossy().contains("owner/repo"));
}
#[test]
fn test_try_github_shorthand_not_shorthand() {
let result = try_github_shorthand("owner/repo");
assert!(result.is_none());
}
#[test]
fn test_try_github_url_https() {
let result = try_github_url("https://github.com/owner/repo");
assert!(result.is_some());
let path = result.unwrap().unwrap();
assert_eq!(path.to_string_lossy(), "https://github.com/owner/repo");
}
#[test]
fn test_try_github_url_git() {
let result = try_github_url("git@github.com:owner/repo");
assert!(result.is_some());
let path = result.unwrap().unwrap();
assert_eq!(path.to_string_lossy(), "git@github.com:owner/repo");
}
#[test]
fn test_try_github_url_not_github() {
let result = try_github_url("https://gitlab.com/owner/repo");
assert!(result.is_none());
}
#[test]
fn test_try_owner_repo_format() {
let result = try_owner_repo_format("owner/repo");
assert!(result.is_some());
let path = result.unwrap().unwrap();
assert!(path.to_string_lossy().contains("github.com"));
assert!(path.to_string_lossy().contains("owner/repo"));
}
#[test]
fn test_try_owner_repo_format_with_dot() {
let result = try_owner_repo_format("owner.name/repo");
assert!(result.is_none());
}
#[test]
fn test_try_owner_repo_format_no_slash() {
let result = try_owner_repo_format("owner-repo");
assert!(result.is_none());
}
#[test]
fn test_find_git_root_direct() {
let temp_dir = TempDir::new().unwrap();
std::fs::create_dir(temp_dir.path().join(".git")).unwrap();
let result = find_git_root(temp_dir.path());
assert!(result.is_some());
assert_eq!(result.unwrap(), temp_dir.path());
}
#[test]
fn test_find_git_root_parent() {
let temp_dir = TempDir::new().unwrap();
std::fs::create_dir(temp_dir.path().join(".git")).unwrap();
let sub_dir = temp_dir.path().join("subdir");
std::fs::create_dir(&sub_dir).unwrap();
let result = find_git_root(&sub_dir);
assert!(result.is_some());
assert_eq!(result.unwrap(), temp_dir.path());
}
#[test]
fn test_find_git_root_not_found() {
let temp_dir = TempDir::new().unwrap();
let result = find_git_root(temp_dir.path());
assert!(result.is_none());
}
#[test]
fn test_get_canonical_path_some() {
let temp_dir = TempDir::new().unwrap();
let result = get_canonical_path(Some(temp_dir.path().to_path_buf()));
assert!(result.is_ok());
}
#[test]
fn test_get_canonical_path_none() {
let result = get_canonical_path(None);
assert!(result.is_ok());
}
#[test]
fn test_get_canonical_path_nonexistent() {
let result = get_canonical_path(Some(PathBuf::from("/nonexistent/path/xyz")));
assert!(result.is_err());
assert!(result.unwrap_err().to_string().contains("does not exist"));
}
#[test]
fn test_resolve_repository_with_url() {
let result = resolve_repository(
None,
Some("https://github.com/owner/repo".to_string()),
None,
);
assert!(result.is_ok());
let path = result.unwrap();
assert!(path.to_string_lossy().contains("github.com"));
}
#[test]
fn test_resolve_repository_with_repo_shorthand() {
let result = resolve_repository(None, None, Some("gh:owner/repo".to_string()));
assert!(result.is_ok());
let path = result.unwrap();
assert!(path.to_string_lossy().contains("github.com"));
}
#[test]
fn test_resolve_repository_with_local_path() {
let temp_dir = TempDir::new().unwrap();
std::fs::create_dir(temp_dir.path().join(".git")).unwrap();
let result = resolve_repository(Some(temp_dir.path().to_path_buf()), None, None);
assert!(result.is_ok());
}
#[test]
fn test_is_interactive_environment_in_ci() {
let _result = is_interactive_environment();
}
#[test]
fn test_resolve_repo_spec_local_path() {
let temp_dir = TempDir::new().unwrap();
std::fs::create_dir(temp_dir.path().join(".git")).unwrap();
let path_str = temp_dir.path().to_string_lossy().to_string();
let result = resolve_repo_spec(&path_str);
assert!(result.is_ok());
}
#[test]
fn test_resolve_repo_spec_github_shorthand() {
let result = resolve_repo_spec("gh:owner/repo");
assert!(result.is_ok());
let path = result.unwrap();
assert!(path.to_string_lossy().contains("github.com"));
}
#[test]
fn test_resolve_repo_spec_github_url() {
let result = resolve_repo_spec("https://github.com/owner/repo");
assert!(result.is_ok());
}
#[test]
fn test_resolve_repo_spec_owner_repo() {
let result = resolve_repo_spec("owner/repo");
assert!(result.is_ok());
let path = result.unwrap();
assert!(path.to_string_lossy().contains("github.com"));
}
#[test]
fn test_resolve_repo_spec_not_found() {
let result = resolve_repo_spec("nonexistent-path-that-definitely-does-not-exist");
assert!(result.is_err());
assert!(result.unwrap_err().to_string().contains("not found"));
}
#[test]
fn test_detect_repository_with_git() {
let temp_dir = TempDir::new().unwrap();
std::fs::create_dir(temp_dir.path().join(".git")).unwrap();
let result = detect_repository(Some(temp_dir.path().to_path_buf()));
assert!(result.is_ok());
assert_eq!(result.unwrap(), temp_dir.path());
}
#[test]
fn test_resolve_repository_priority_repo_over_url() {
let result = resolve_repository(
None,
Some("https://github.com/other/repo".to_string()),
Some("gh:owner/main-repo".to_string()),
);
assert!(result.is_ok());
let path = result.unwrap();
assert!(path.to_string_lossy().contains("owner/main-repo"));
}
#[test]
fn test_resolve_repository_priority_url_over_path() {
let temp_dir = TempDir::new().unwrap();
std::fs::create_dir(temp_dir.path().join(".git")).unwrap();
let result = resolve_repository(
Some(temp_dir.path().to_path_buf()),
Some("https://github.com/test/repo".to_string()),
None,
);
assert!(result.is_ok());
let path = result.unwrap();
assert!(path.to_string_lossy().contains("github.com"));
}
#[test]
fn test_resolve_repo_spec_git_ssh_url() {
let result = resolve_repo_spec("git@github.com:owner/repo.git");
assert!(result.is_ok());
let path = result.unwrap();
assert_eq!(path.to_string_lossy(), "git@github.com:owner/repo.git");
}
#[test]
fn test_find_git_root_deeply_nested() {
let temp_dir = TempDir::new().unwrap();
std::fs::create_dir(temp_dir.path().join(".git")).unwrap();
let mut nested = temp_dir.path().to_path_buf();
for i in 0..10 {
nested = nested.join(format!("level{i}"));
std::fs::create_dir(&nested).unwrap();
}
let result = find_git_root(&nested);
assert!(result.is_some());
assert_eq!(result.unwrap(), temp_dir.path());
}
#[test]
fn test_find_git_root_at_filesystem_root() {
let result = find_git_root(Path::new("/"));
assert!(result.is_none());
}
#[test]
fn test_detect_repository_no_git_non_interactive() {
let temp_dir = TempDir::new().unwrap();
let result = detect_repository(Some(temp_dir.path().to_path_buf()));
let _ = result;
}
#[tokio::test]
async fn test_resolve_repository_async_local_path() {
let temp_dir = TempDir::new().unwrap();
std::fs::create_dir(temp_dir.path().join(".git")).unwrap();
let result =
resolve_repository_async(Some(temp_dir.path().to_path_buf()), None, None).await;
assert!(result.is_ok());
let path = result.unwrap();
assert!(path.exists());
}
#[tokio::test]
async fn test_resolve_repository_async_with_shorthand() {
let result = resolve_repository_async(None, None, Some("gh:rust-lang/rust".to_string()));
match result.await {
Ok(path) => {
assert!(path.to_string_lossy().len() > 0);
}
Err(e) => {
let err_str = e.to_string();
assert!(
err_str.contains("clone")
|| err_str.contains("git")
|| err_str.contains("timeout")
|| err_str.contains("network")
|| err_str.contains("error")
);
}
}
}