diff options
Diffstat (limited to 'test_utilities/src')
| -rw-r--r-- | test_utilities/src/lib.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test_utilities/src/lib.rs b/test_utilities/src/lib.rs new file mode 100644 index 0000000..cb69853 --- /dev/null +++ b/test_utilities/src/lib.rs @@ -0,0 +1,34 @@ +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()); +} |