feat: add helper functions for creating temporary files with random binary content and asserting file sizes

Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-15 11:26:25 -03:00
parent 60ec6da886
commit 2f78e45444

View File

@@ -183,3 +183,24 @@ pub fn create_nested_temp_dir_structure(dir: &TempDir) -> (PathBuf, PathBuf, Pat
(level1, level2, level3) (level1, level2, level3)
} }
/// Create a temporary file with random binary content of specified size
pub fn create_temp_file_with_random_binary_content(dir: &TempDir, filename: &str, size: usize) -> PathBuf {
use rand::Rng;
let mut rng = rand::thread_rng();
let random_data: Vec<u8> = (0..size).map(|_| rng.gen()).collect();
create_temp_file_with_binary_content(dir, filename, &random_data)
}
/// Assert that a file has the expected size
pub fn assert_file_size(file_path: &PathBuf, expected_size: u64) {
let actual_size = get_file_size(file_path);
assert_eq!(actual_size, expected_size, "File {:?} has size {} but expected {}", file_path, actual_size, expected_size);
}
/// Create multiple temporary files with content in a directory
pub fn create_multiple_temp_files_with_content(dir: &TempDir, files: &[(&str, &str)]) -> Vec<PathBuf> {
files.iter().map(|(filename, content)| {
create_temp_file_with_content(dir, filename, content)
}).collect()
}