feat: Convert SAL to a Rust monorepo
Some checks are pending
Rhai Tests / Run Rhai Tests (push) Waiting to run
Some checks are pending
Rhai Tests / Run Rhai Tests (push) Waiting to run
- Migrate SAL project from single-crate to monorepo structure - Create independent packages for individual modules - Improve build efficiency and testing capabilities - Update documentation to reflect new structure - Successfully convert the git module to an independent package.
This commit is contained in:
119
git/tests/git_tests.rs
Normal file
119
git/tests/git_tests.rs
Normal file
@@ -0,0 +1,119 @@
|
||||
use sal_git::*;
|
||||
use std::fs;
|
||||
use tempfile::TempDir;
|
||||
|
||||
#[test]
|
||||
fn test_parse_git_url_https() {
|
||||
let (server, account, repo) = parse_git_url("https://github.com/user/repo.git");
|
||||
assert_eq!(server, "github.com");
|
||||
assert_eq!(account, "user");
|
||||
assert_eq!(repo, "repo");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_git_url_https_without_git_extension() {
|
||||
let (server, account, repo) = parse_git_url("https://github.com/user/repo");
|
||||
assert_eq!(server, "github.com");
|
||||
assert_eq!(account, "user");
|
||||
assert_eq!(repo, "repo");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_git_url_ssh() {
|
||||
let (server, account, repo) = parse_git_url("git@github.com:user/repo.git");
|
||||
assert_eq!(server, "github.com");
|
||||
assert_eq!(account, "user");
|
||||
assert_eq!(repo, "repo");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_git_url_ssh_without_git_extension() {
|
||||
let (server, account, repo) = parse_git_url("git@github.com:user/repo");
|
||||
assert_eq!(server, "github.com");
|
||||
assert_eq!(account, "user");
|
||||
assert_eq!(repo, "repo");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_git_url_invalid() {
|
||||
let (server, account, repo) = parse_git_url("invalid-url");
|
||||
assert_eq!(server, "");
|
||||
assert_eq!(account, "");
|
||||
assert_eq!(repo, "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_git_tree_new_creates_directory() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let base_path = temp_dir.path().join("git_repos");
|
||||
let base_path_str = base_path.to_str().unwrap();
|
||||
|
||||
let _git_tree = GitTree::new(base_path_str).unwrap();
|
||||
assert!(base_path.exists());
|
||||
assert!(base_path.is_dir());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_git_tree_new_existing_directory() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let base_path = temp_dir.path().join("existing_dir");
|
||||
fs::create_dir_all(&base_path).unwrap();
|
||||
let base_path_str = base_path.to_str().unwrap();
|
||||
|
||||
let _git_tree = GitTree::new(base_path_str).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_git_tree_new_invalid_path() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let file_path = temp_dir.path().join("file.txt");
|
||||
fs::write(&file_path, "content").unwrap();
|
||||
let file_path_str = file_path.to_str().unwrap();
|
||||
|
||||
let result = GitTree::new(file_path_str);
|
||||
assert!(result.is_err());
|
||||
if let Err(error) = result {
|
||||
match error {
|
||||
GitError::InvalidBasePath(_) => {}
|
||||
_ => panic!("Expected InvalidBasePath error"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_git_tree_list_empty_directory() {
|
||||
let temp_dir = TempDir::new().unwrap();
|
||||
let base_path_str = temp_dir.path().to_str().unwrap();
|
||||
|
||||
let git_tree = GitTree::new(base_path_str).unwrap();
|
||||
let repos = git_tree.list().unwrap();
|
||||
assert!(repos.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_git_repo_new() {
|
||||
let repo = GitRepo::new("/path/to/repo".to_string());
|
||||
assert_eq!(repo.path(), "/path/to/repo");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_git_repo_clone() {
|
||||
let repo1 = GitRepo::new("/path/to/repo".to_string());
|
||||
let repo2 = repo1.clone();
|
||||
assert_eq!(repo1.path(), repo2.path());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_git_error_display() {
|
||||
let error = GitError::InvalidUrl("bad-url".to_string());
|
||||
assert_eq!(format!("{}", error), "Could not parse git URL: bad-url");
|
||||
|
||||
let error = GitError::NoRepositoriesFound;
|
||||
assert_eq!(format!("{}", error), "No repositories found");
|
||||
|
||||
let error = GitError::RepositoryNotFound("pattern".to_string());
|
||||
assert_eq!(
|
||||
format!("{}", error),
|
||||
"No repositories found matching 'pattern'"
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user