feat: add test helpers for database setup and file content comparison
Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -89,3 +89,34 @@ pub fn test_compression_engine(engine: &dyn crate::compression_engine::Compressi
|
|||||||
|
|
||||||
assert_eq!(test_data, decompressed.as_slice());
|
assert_eq!(test_data, decompressed.as_slice());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create a test database with some initial data
|
||||||
|
pub fn create_test_db_with_data() -> (TempDir, Connection, PathBuf) {
|
||||||
|
let (temp_dir, conn, db_path) = create_temp_db();
|
||||||
|
|
||||||
|
// Add some test items
|
||||||
|
let item1 = crate::db::Item {
|
||||||
|
id: None,
|
||||||
|
ts: chrono::Utc::now(),
|
||||||
|
size: Some(100),
|
||||||
|
compression: crate::compression_engine::CompressionType::None.to_string(),
|
||||||
|
};
|
||||||
|
db::insert_item(&conn, item1).expect("Failed to insert item1");
|
||||||
|
|
||||||
|
let item2 = crate::db::Item {
|
||||||
|
id: None,
|
||||||
|
ts: chrono::Utc::now(),
|
||||||
|
size: Some(200),
|
||||||
|
compression: crate::compression_engine::CompressionType::LZ4.to_string(),
|
||||||
|
};
|
||||||
|
db::insert_item(&conn, item2).expect("Failed to insert item2");
|
||||||
|
|
||||||
|
(temp_dir, conn, db_path)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Assert that two paths point to files with identical content
|
||||||
|
pub fn assert_files_equal(path1: &PathBuf, path2: &PathBuf) {
|
||||||
|
let content1 = std::fs::read(path1).expect("Failed to read first file");
|
||||||
|
let content2 = std::fs::read(path2).expect("Failed to read second file");
|
||||||
|
assert_eq!(content1, content2, "Files {:?} and {:?} have different content", path1, path2);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user