use std::fs;
use tempfile::TempDir;
#[test]
fn test_atomic_write() {
let temp_dir = TempDir::new().unwrap();
let file_path = temp_dir.path().join("test.txt");
let content = b"Hello, World!";
fs::write(&file_path, content).unwrap();
let read_content = fs::read(&file_path).unwrap();
assert_eq!(read_content, content);
}
#[test]
fn test_config_file_permissions() {
let temp_dir = TempDir::new().unwrap();
let file_path = temp_dir.path().join("readonly.txt");
fs::write(&file_path, b"test").unwrap();
let metadata = fs::metadata(&file_path).unwrap();
assert!(metadata.is_file());
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
let perms = metadata.permissions();
let mode = perms.mode();
let has_write = (mode & 0o200) != 0;
assert!(has_write, "File should be writable initially");
}
}
#[test]
fn test_symlink_resolution() {
let temp_dir = TempDir::new().unwrap();
let target_file = temp_dir.path().join("target.txt");
let link_path = temp_dir.path().join("link.txt");
fs::write(&target_file, b"target content").unwrap();
#[cfg(unix)]
{
std::os::unix::fs::symlink(&target_file, &link_path).unwrap();
assert!(link_path.exists());
let metadata = fs::metadata(&link_path).unwrap();
assert!(metadata.is_file());
}
}