From 2f78e4544464c0b6bc1b8293c5dac0f51139aa8d Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Fri, 15 Aug 2025 11:26:25 -0300 Subject: [PATCH] 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) --- src/tests/common/test_helpers.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/tests/common/test_helpers.rs b/src/tests/common/test_helpers.rs index dcd50cf..9a1f0c1 100644 --- a/src/tests/common/test_helpers.rs +++ b/src/tests/common/test_helpers.rs @@ -183,3 +183,24 @@ pub fn create_nested_temp_dir_structure(dir: &TempDir) -> (PathBuf, PathBuf, Pat (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 = (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 { + files.iter().map(|(filename, content)| { + create_temp_file_with_content(dir, filename, content) + }).collect() +}