From 31cb23502398501e03b193e2b228058704dd7811 Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Fri, 15 Aug 2025 13:07:15 -0300 Subject: [PATCH] refactor: replace direct file existence checks with test helpers Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) --- src/tests/modes/delete_tests.rs | 4 ++-- src/tests/modes/get_tests.rs | 4 ++-- src/tests/modes/info_tests.rs | 7 +++---- src/tests/modes/save_tests.rs | 9 ++++----- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/tests/modes/delete_tests.rs b/src/tests/modes/delete_tests.rs index 4755228..538ad4b 100644 --- a/src/tests/modes/delete_tests.rs +++ b/src/tests/modes/delete_tests.rs @@ -1,6 +1,6 @@ #[cfg(test)] mod tests { - use crate::tests::common::test_helpers::{create_temp_dir, create_empty_temp_file}; + use crate::tests::common::test_helpers::{create_temp_dir, create_empty_temp_file, assert_file_exists}; #[test] fn test_delete_mode_setup() { @@ -15,6 +15,6 @@ mod tests { let test_file = create_empty_temp_file(&temp_dir, "test_delete.txt"); // Verify file exists before deletion test - assert!(test_file.exists()); + assert_file_exists(&test_file); } } diff --git a/src/tests/modes/get_tests.rs b/src/tests/modes/get_tests.rs index 40c01ff..0ad27dd 100644 --- a/src/tests/modes/get_tests.rs +++ b/src/tests/modes/get_tests.rs @@ -1,6 +1,6 @@ #[cfg(test)] mod tests { - use crate::tests::common::test_helpers::{create_temp_dir, test_temp_dir_setup}; + use crate::tests::common::test_helpers::{create_temp_dir, test_temp_dir_setup, assert_file_not_exists}; #[test] fn test_get_mode_basic_setup() { @@ -14,6 +14,6 @@ mod tests { let test_file = temp_dir.path().join("test_get.txt"); // Test path creation - assert!(!test_file.exists()); + assert_file_not_exists(&test_file); } } diff --git a/src/tests/modes/info_tests.rs b/src/tests/modes/info_tests.rs index e5d746c..e13ce4d 100644 --- a/src/tests/modes/info_tests.rs +++ b/src/tests/modes/info_tests.rs @@ -1,6 +1,6 @@ #[cfg(test)] mod tests { - use crate::tests::common::test_helpers::{create_temp_dir, test_file_creation}; + use crate::tests::common::test_helpers::{create_temp_dir, test_file_creation, assert_file_not_exists, get_file_size}; use std::path::PathBuf; #[test] @@ -11,8 +11,7 @@ mod tests { let file_path = test_file_creation(&dir, "info_test.txt", content); // Additional verification specific to info mode - let metadata = std::fs::metadata(&file_path).expect("Failed to get file metadata"); - assert!(metadata.len() > 0); + assert!(get_file_size(&file_path) > 0); } #[test] @@ -21,6 +20,6 @@ mod tests { let nonexistent_path = PathBuf::from("/nonexistent/file/path.txt"); // Verify the file doesn't exist - assert!(!nonexistent_path.exists()); + assert_file_not_exists(&nonexistent_path); } } diff --git a/src/tests/modes/save_tests.rs b/src/tests/modes/save_tests.rs index ba2942b..35759ff 100644 --- a/src/tests/modes/save_tests.rs +++ b/src/tests/modes/save_tests.rs @@ -1,6 +1,6 @@ #[cfg(test)] mod tests { - use crate::tests::common::test_helpers::{create_temp_dir, create_temp_file_with_content, create_empty_temp_file}; + use crate::tests::common::test_helpers::{create_temp_dir, create_temp_file_with_content, create_empty_temp_file, assert_file_exists, get_file_size}; #[test] fn test_save_mode_basic_functionality() { @@ -9,7 +9,7 @@ mod tests { let file_path = create_temp_file_with_content(&dir, "test_input.txt", "test content for save mode\n"); // Verify file was created - assert!(file_path.exists()); + assert_file_exists(&file_path); // Note: Actual save mode testing would require integration with the keep database // and compression engines, which is complex for unit tests @@ -22,8 +22,7 @@ mod tests { let file_path = create_empty_temp_file(&dir, "empty_test.txt"); // Verify empty file was created - assert!(file_path.exists()); - let metadata = std::fs::metadata(&file_path).expect("Failed to get file metadata"); - assert_eq!(metadata.len(), 0); + assert_file_exists(&file_path); + assert_eq!(get_file_size(&file_path), 0); } }