use anyhow::Result;
#[tokio::test]
async fn test_validate_hooks_config_success() -> Result<()> {
let result = guardy::hooks::validate::validate_hooks_config().await;
assert!(
result.is_ok(),
"Default hooks config should validate successfully: {result:?}"
);
Ok(())
}
#[tokio::test]
async fn test_validate_empty_config() -> Result<()> {
let result = guardy::hooks::validate::validate_hooks_config().await;
assert!(
result.is_ok(),
"Empty hooks config should validate with warnings: {result:?}"
);
Ok(())
}
#[tokio::test]
async fn test_validate_hook_definition_structure() -> Result<()> {
let result = guardy::hooks::validate::validate_hooks_config().await;
assert!(
result.is_ok() || result.is_err(),
"Validation should complete without panicking"
);
Ok(())
}
#[tokio::test]
async fn test_validate_with_configuration_loaded() -> Result<()> {
let hooks_config = &guardy::config::CONFIG.hooks;
let _pre_commit_len = hooks_config.pre_commit.commands.len();
let _commit_msg_len = hooks_config.commit_msg.commands.len();
let result = guardy::hooks::validate::validate_hooks_config().await;
assert!(
result.is_ok(),
"Loaded hooks config should validate: {result:?}"
);
Ok(())
}
#[tokio::test]
async fn test_validate_glob_pattern_handling() -> Result<()> {
let result = guardy::hooks::validate::validate_hooks_config().await;
assert!(
result.is_ok() || result.is_err(),
"Should handle glob patterns gracefully"
);
Ok(())
}
#[tokio::test]
async fn test_validate_all_hook_types() -> Result<()> {
let result = guardy::hooks::validate::validate_hooks_config().await;
assert!(result.is_ok(), "Should validate all hook types: {result:?}");
Ok(())
}
#[tokio::test]
async fn test_validate_returns_appropriate_result() -> Result<()> {
let result = guardy::hooks::validate::validate_hooks_config().await;
match result {
Ok(()) => {
}
Err(e) => {
let error_msg = e.to_string();
assert!(!error_msg.is_empty(), "Error message should not be empty");
assert!(
error_msg.contains("error") || error_msg.contains("Error"),
"Error message should indicate validation failure: {error_msg}"
);
}
}
Ok(())
}
#[tokio::test]
async fn test_validate_performance() -> Result<()> {
use std::time::Instant;
let start = Instant::now();
let result = guardy::hooks::validate::validate_hooks_config().await;
let duration = start.elapsed();
assert!(
duration.as_secs() < 1,
"Validation should complete quickly, took: {duration:?}"
);
assert!(
result.is_ok() || result.is_err(),
"Should complete without timeout"
);
Ok(())
}
#[tokio::test]
async fn test_validate_handles_empty_strings() -> Result<()> {
let result = guardy::hooks::validate::validate_hooks_config().await;
assert!(
result.is_ok() || result.is_err(),
"Should handle empty strings gracefully"
);
Ok(())
}