feat: add compression engine test helpers and refactor tests
Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -62,3 +62,30 @@ pub fn create_test_item(conn: &Connection) -> i64 {
|
||||
};
|
||||
db::insert_item(conn, item).expect("Failed to insert item")
|
||||
}
|
||||
|
||||
/// Create a test file with compression engine testing data
|
||||
pub fn create_test_file_with_data(dir: &TempDir, filename: &str, data: &[u8]) -> PathBuf {
|
||||
let file_path = dir.path().join(filename);
|
||||
let mut file = File::create(&file_path).expect("Failed to create test file");
|
||||
file.write_all(data).expect("Failed to write to test file");
|
||||
file_path
|
||||
}
|
||||
|
||||
/// Test compression and decompression with an engine
|
||||
pub fn test_compression_engine(engine: &dyn crate::compression_engine::CompressionEngine, test_data: &[u8]) {
|
||||
let dir = create_temp_dir();
|
||||
let file_path = dir.path().join("test_compression.dat");
|
||||
|
||||
// Test compression
|
||||
{
|
||||
let mut writer = engine.create(file_path.clone()).expect("Failed to create writer");
|
||||
writer.write_all(test_data).expect("Failed to write data");
|
||||
}
|
||||
|
||||
// Test decompression
|
||||
let mut reader = engine.open(file_path).expect("Failed to open reader");
|
||||
let mut decompressed = Vec::new();
|
||||
std::io::copy(&mut reader, &mut decompressed).expect("Failed to read data");
|
||||
|
||||
assert_eq!(test_data, decompressed.as_slice());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user