#![allow(deprecated)]
use tempfile::TempDir;
use tree_type::tree_type;
#[allow(dead_code)]
fn default_config(_config: &TestRootConfig) -> Result<String, std::io::Error> {
Ok("default config content".to_string())
}
tree_type! {
TestRoot {
#[default(default_config)]
config("config.toml")
}
}
#[test]
fn test_ensure_creates_file_with_default() {
let temp_dir = TempDir::new().unwrap();
let root = TestRoot::new(temp_dir.path()).unwrap();
assert!(!root.config().exists(), "Config should not exist initially");
let result = root.sync();
assert!(result.is_ok(), "Sync should succeed: {:?}", result);
assert!(root.config().exists(), "Config should exist after ensure");
let content = std::fs::read_to_string(root.config().as_path()).unwrap();
assert_eq!(
content, "default config content",
"Should have default content"
);
}
#[test]
fn test_ensure_skips_existing_file_with_default() {
let temp_dir = TempDir::new().unwrap();
let root = TestRoot::new(temp_dir.path()).unwrap();
std::fs::write(root.config().as_path(), "custom content").unwrap();
let result = root.sync();
assert!(result.is_ok(), "Sync should succeed: {:?}", result);
let content = std::fs::read_to_string(root.config().as_path()).unwrap();
assert_eq!(
content, "custom content",
"Should preserve existing content"
);
}