1 use std::env::temp_dir;
2 use std::fs::{create_dir_all, read_to_string, remove_dir_all, File};
4 use std::path::PathBuf;
5 use std::time::{SystemTime, UNIX_EPOCH};
8 pub fn setup_test_dir() -> PathBuf {
9 let timestamp = SystemTime::now()
10 .duration_since(UNIX_EPOCH)
13 let process_id = id();
14 let test_dir = temp_dir().join(format!("page_test_{}_{}", timestamp, process_id));
15 create_dir_all(&test_dir)
16 .expect("Could not create test directory");
20 pub fn cleanup_test_dir(test_dir: &PathBuf) {
21 if test_dir.exists() {
22 remove_dir_all(test_dir).unwrap();
26 pub fn create_test_file(path: &PathBuf, content: &str) {
27 let mut file = File::create(path).unwrap();
28 file.write_all(content.as_bytes()).unwrap();
31 pub fn assert_file_contents(path: &PathBuf, expected: &str) {
32 let content = read_to_string(path).unwrap();
33 assert_eq!(content.trim(), expected.trim());