use std::env::temp_dir; use std::fs::{create_dir_all, read_to_string, remove_dir_all, File}; use std::io::Write; use std::path::PathBuf; use std::time::{SystemTime, UNIX_EPOCH}; use std::process::id; pub fn setup_test_dir() -> PathBuf { let timestamp = SystemTime::now() .duration_since(UNIX_EPOCH) .unwrap() .as_nanos(); let process_id = id(); let test_dir = temp_dir().join(format!("page_test_{}_{}", timestamp, process_id)); create_dir_all(&test_dir) .expect("Could not create test directory"); test_dir } pub fn cleanup_test_dir(test_dir: &PathBuf) { if test_dir.exists() { remove_dir_all(test_dir).unwrap(); } } pub fn create_test_file(path: &PathBuf, content: &str) { let mut file = File::create(path).unwrap(); file.write_all(content.as_bytes()).unwrap(); } pub fn assert_file_contents(path: &PathBuf, expected: &str) { let content = read_to_string(path).unwrap(); assert_eq!(content.trim(), expected.trim()); }