use anyhow::Result;
#[tokio::test]
async fn test_dump_hooks_config_json() -> Result<()> {
let result = guardy::hooks::dump::dump_hooks_config(Some("json".to_string())).await;
assert!(result.is_ok(), "Dump JSON should succeed: {result:?}");
Ok(())
}
#[tokio::test]
async fn test_dump_hooks_config_yaml() -> Result<()> {
let result = guardy::hooks::dump::dump_hooks_config(Some("yaml".to_string())).await;
assert!(result.is_ok(), "Dump YAML should succeed: {result:?}");
Ok(())
}
#[tokio::test]
async fn test_dump_hooks_config_toml() -> Result<()> {
let result = guardy::hooks::dump::dump_hooks_config(Some("toml".to_string())).await;
assert!(result.is_ok(), "Dump TOML should succeed: {result:?}");
Ok(())
}
#[tokio::test]
async fn test_dump_hooks_config_default_format() -> Result<()> {
let result = guardy::hooks::dump::dump_hooks_config(None).await;
assert!(
result.is_ok(),
"Dump default format should succeed: {result:?}"
);
Ok(())
}
#[tokio::test]
async fn test_dump_hooks_config_invalid_format() -> Result<()> {
let result = guardy::hooks::dump::dump_hooks_config(Some("xml".to_string())).await;
assert!(result.is_err(), "Dump invalid format should fail");
let error_msg = result.unwrap_err().to_string();
assert!(
error_msg.contains("Unsupported output format"),
"Error should mention unsupported format"
);
Ok(())
}
#[tokio::test]
async fn test_dump_lefthook_config() -> Result<()> {
let result = guardy::hooks::dump::dump_lefthook_config().await;
assert!(
result.is_ok(),
"Dump lefthook config should succeed: {result:?}"
);
Ok(())
}
#[tokio::test]
async fn test_dump_json_is_valid() -> Result<()> {
let hooks_config = &guardy::config::CONFIG.hooks;
let json_output = serde_json::to_string_pretty(&**hooks_config)?;
let parsed: serde_json::Value = serde_json::from_str(&json_output)?;
assert!(parsed.is_object(), "JSON should be an object");
Ok(())
}
#[tokio::test]
async fn test_dump_yaml_is_valid() -> Result<()> {
let hooks_config = &guardy::config::CONFIG.hooks;
let yaml_output = serde_yaml_bw::to_string(&**hooks_config)?;
let parsed: serde_yaml_bw::Value = serde_yaml_bw::from_str(&yaml_output)?;
assert!(parsed.is_mapping(), "YAML should be a mapping");
Ok(())
}
#[tokio::test]
async fn test_dump_toml_is_valid() -> Result<()> {
let hooks_config = &guardy::config::CONFIG.hooks;
let toml_output = toml::to_string_pretty(&**hooks_config)?;
let parsed: toml::Value = toml::from_str(&toml_output)?;
assert!(parsed.is_table(), "TOML should be a table");
Ok(())
}