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.
140 lines
4.1 KiB
Rust
140 lines
4.1 KiB
Rust
use sal_git::*;
|
|
use std::collections::HashMap;
|
|
|
|
#[test]
|
|
fn test_git_executor_new() {
|
|
let executor = GitExecutor::new();
|
|
// We can't directly access the config field since it's private,
|
|
// but we can test that the executor was created successfully
|
|
let _executor = executor;
|
|
}
|
|
|
|
#[test]
|
|
fn test_git_executor_default() {
|
|
let executor = GitExecutor::default();
|
|
let _executor = executor;
|
|
}
|
|
|
|
#[test]
|
|
fn test_git_config_status_serialization() {
|
|
let status_ok = GitConfigStatus::Ok;
|
|
let status_error = GitConfigStatus::Error;
|
|
|
|
let json_ok = serde_json::to_string(&status_ok).unwrap();
|
|
let json_error = serde_json::to_string(&status_error).unwrap();
|
|
|
|
assert_eq!(json_ok, "\"ok\"");
|
|
assert_eq!(json_error, "\"error\"");
|
|
}
|
|
|
|
#[test]
|
|
fn test_git_config_status_deserialization() {
|
|
let status_ok: GitConfigStatus = serde_json::from_str("\"ok\"").unwrap();
|
|
let status_error: GitConfigStatus = serde_json::from_str("\"error\"").unwrap();
|
|
|
|
assert_eq!(status_ok, GitConfigStatus::Ok);
|
|
assert_eq!(status_error, GitConfigStatus::Error);
|
|
}
|
|
|
|
#[test]
|
|
fn test_git_server_auth_serialization() {
|
|
let auth = GitServerAuth {
|
|
sshagent: Some(true),
|
|
key: None,
|
|
username: None,
|
|
password: None,
|
|
};
|
|
|
|
let json = serde_json::to_string(&auth).unwrap();
|
|
assert!(json.contains("\"sshagent\":true"));
|
|
}
|
|
|
|
#[test]
|
|
fn test_git_server_auth_deserialization() {
|
|
let json = r#"{"sshagent":true,"key":null,"username":null,"password":null}"#;
|
|
let auth: GitServerAuth = serde_json::from_str(json).unwrap();
|
|
|
|
assert_eq!(auth.sshagent, Some(true));
|
|
assert_eq!(auth.key, None);
|
|
assert_eq!(auth.username, None);
|
|
assert_eq!(auth.password, None);
|
|
}
|
|
|
|
#[test]
|
|
fn test_git_config_serialization() {
|
|
let mut auth_map = HashMap::new();
|
|
auth_map.insert(
|
|
"github.com".to_string(),
|
|
GitServerAuth {
|
|
sshagent: Some(true),
|
|
key: None,
|
|
username: None,
|
|
password: None,
|
|
},
|
|
);
|
|
|
|
let config = GitConfig {
|
|
status: GitConfigStatus::Ok,
|
|
auth: auth_map,
|
|
};
|
|
|
|
let json = serde_json::to_string(&config).unwrap();
|
|
assert!(json.contains("\"status\":\"ok\""));
|
|
assert!(json.contains("\"github.com\""));
|
|
}
|
|
|
|
#[test]
|
|
fn test_git_config_deserialization() {
|
|
let json = r#"{"status":"ok","auth":{"github.com":{"sshagent":true,"key":null,"username":null,"password":null}}}"#;
|
|
let config: GitConfig = serde_json::from_str(json).unwrap();
|
|
|
|
assert_eq!(config.status, GitConfigStatus::Ok);
|
|
assert!(config.auth.contains_key("github.com"));
|
|
assert_eq!(config.auth["github.com"].sshagent, Some(true));
|
|
}
|
|
|
|
#[test]
|
|
fn test_git_executor_error_display() {
|
|
let error = GitExecutorError::GitCommandFailed("command failed".to_string());
|
|
assert_eq!(format!("{}", error), "Git command failed: command failed");
|
|
|
|
let error = GitExecutorError::SshAgentNotLoaded;
|
|
assert_eq!(format!("{}", error), "SSH agent is not loaded");
|
|
|
|
let error = GitExecutorError::AuthenticationError("auth failed".to_string());
|
|
assert_eq!(format!("{}", error), "Authentication error: auth failed");
|
|
}
|
|
|
|
#[test]
|
|
fn test_git_executor_error_from_redis_error() {
|
|
let redis_error = redis::RedisError::from((redis::ErrorKind::TypeError, "type error"));
|
|
let git_error = GitExecutorError::from(redis_error);
|
|
|
|
match git_error {
|
|
GitExecutorError::RedisError(_) => {}
|
|
_ => panic!("Expected RedisError variant"),
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn test_git_executor_error_from_serde_error() {
|
|
let serde_error = serde_json::from_str::<GitConfig>("invalid json").unwrap_err();
|
|
let git_error = GitExecutorError::from(serde_error);
|
|
|
|
match git_error {
|
|
GitExecutorError::JsonError(_) => {}
|
|
_ => panic!("Expected JsonError variant"),
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn test_git_executor_error_from_io_error() {
|
|
let io_error = std::io::Error::new(std::io::ErrorKind::NotFound, "file not found");
|
|
let git_error = GitExecutorError::from(io_error);
|
|
|
|
match git_error {
|
|
GitExecutorError::CommandExecutionError(_) => {}
|
|
_ => panic!("Expected CommandExecutionError variant"),
|
|
}
|
|
}
|