use crate::cli::*;
fn clear_env() {
std::env::remove_var("MIRAGE_DB");
}
#[test]
fn test_resolve_db_path_no_source() {
clear_env();
let result = resolve_db_path(None);
match result {
Ok(path) => {
assert!(
path.ends_with(".db") || path.ends_with(".db"),
"Auto-discovered DB should have .db or .db extension"
);
}
Err(_) => {
}
}
}
#[test]
fn test_resolve_db_path_with_cli_arg() {
clear_env();
let result = resolve_db_path(Some("/custom/path.db".to_string())).unwrap();
assert_eq!(result, "/custom/path.db");
}
#[test]
fn test_resolve_db_path_with_env_var() {
clear_env();
std::env::set_var("MIRAGE_DB", "/env/path.db");
let result = resolve_db_path(None);
assert!(
result.is_ok(),
"Expected Ok with MIRAGE_DB set, got: {:?}",
result
);
assert_eq!(result.unwrap(), "/env/path.db");
std::env::remove_var("MIRAGE_DB");
}
#[test]
fn test_resolve_db_path_cli_overrides_env() {
clear_env();
std::env::set_var("MIRAGE_DB", "/env/path.db");
let result = resolve_db_path(Some("/cli/path.db".to_string())).unwrap();
assert_eq!(result, "/cli/path.db");
std::env::remove_var("MIRAGE_DB");
}