use clap::Parser;
use tempfile::TempDir;
use ssh_mcp::config::Args;
#[test]
fn test_logging_config_defaults() {
let args = Args::try_parse_from(["ssh-mcp", "--host=test", "--user=test"]).unwrap();
assert_eq!(args.log_level, "info");
assert!(args.log_file.is_none());
assert_eq!(args.log_format, "text");
}
#[test]
fn test_logging_config_with_file() {
let temp_dir = TempDir::new().unwrap();
let log_file = temp_dir.path().join("test.log");
let args = Args::try_parse_from([
"ssh-mcp",
"--host=test",
"--user=test",
"--log-file",
log_file.to_str().unwrap(),
"--log-format=json",
"--log-rotation=daily",
])
.unwrap();
assert_eq!(args.log_level, "info");
assert!(args.log_file.is_some());
assert_eq!(args.log_file.as_deref(), Some(log_file.as_path()));
assert_eq!(args.log_format, "json");
assert_eq!(args.log_rotation, "daily");
}
#[tokio::test]
async fn test_logging_file_integration() {
let temp_dir = TempDir::new().unwrap();
let log_file = temp_dir.path().join("test.log");
let args = Args::try_parse_from([
"ssh-mcp",
"--host=test",
"--user=test",
"--log-file",
log_file.to_str().unwrap(),
"--log-format=json",
"--log-rotation=never",
])
.unwrap();
let _guard = ssh_mcp::logging::init_logging(&args).unwrap();
tracing::info!("Test log message");
drop(_guard);
assert!(log_file.exists(), "Log file not found at {:?}", log_file);
let contents = std::fs::read_to_string(&log_file).unwrap();
assert!(contents.contains("Test log message"));
assert!(contents.contains("\"level\":"));
}