use std::fs;
use tempfile::TempDir;
#[tokio::test]
async fn test_recursive_config_behavior_with_cli() {
use clap::Parser;
use guardy::cli::commands::Cli;
let args = Cli::try_parse_from(["guardy", "--recursive-config=false", "config", "show"]);
assert!(args.is_ok());
let cli = args.unwrap();
assert_eq!(cli.recursive_config, Some(false));
println!("✅ CLI recursive_config flag parsing works correctly");
}
#[tokio::test]
async fn test_recursive_config_env_var_parsing() {
let test_cases = vec![
("0", false),
("false", false),
("FALSE", false),
("no", false),
("1", true),
("true", true),
("TRUE", true),
("yes", true),
];
for (input, expected) in test_cases {
let result = match input {
"1" | "true" | "TRUE" | "yes" | "YES" | "on" | "ON" => true,
"0" | "false" | "FALSE" | "no" | "NO" | "off" | "OFF" => false,
_ => true, };
assert_eq!(result, expected, "Failed for input: {input}");
}
println!("✅ Environment variable parsing logic works correctly");
}
#[tokio::test]
async fn test_recursive_config_file_structure() {
let temp_dir = TempDir::new().expect("Failed to create temp dir");
let parent_dir = temp_dir.path();
let child_dir = parent_dir.join("child");
fs::create_dir_all(&child_dir).expect("Failed to create child directory");
fs::write(
parent_dir.join("guardy.yaml"),
"general:\n debug: true\n recursive_config: true\n",
)
.expect("Failed to write parent config");
fs::write(
child_dir.join("guardy.yaml"),
"general:\n debug: false\n recursive_config: false\n",
)
.expect("Failed to write child config");
assert!(parent_dir.join("guardy.yaml").exists());
assert!(child_dir.join("guardy.yaml").exists());
let child_config =
fs::read_to_string(child_dir.join("guardy.yaml")).expect("Failed to read child config");
assert!(child_config.contains("recursive_config: false"));
let parent_config =
fs::read_to_string(parent_dir.join("guardy.yaml")).expect("Failed to read parent config");
assert!(parent_config.contains("recursive_config: true"));
println!("✅ Config file structure for recursive testing created successfully");
}