Ugh
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
//! Common test utilities and helper functions to reduce duplication in tests
|
||||
|
||||
use tempfile::TempDir;
|
||||
use crate::db;
|
||||
use rusqlite::Connection;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
use rusqlite::Connection;
|
||||
use crate::db;
|
||||
use tempfile::TempDir;
|
||||
|
||||
/// Create a temporary directory for testing
|
||||
pub fn create_temp_dir() -> TempDir {
|
||||
@@ -37,10 +37,10 @@ pub fn test_temp_dir_setup() {
|
||||
pub fn test_file_creation(dir: &TempDir, filename: &str, content: &str) -> PathBuf {
|
||||
let file_path = create_temp_file_with_content(dir, filename, content);
|
||||
assert!(file_path.exists());
|
||||
|
||||
|
||||
let metadata = std::fs::metadata(&file_path).expect("Failed to get file metadata");
|
||||
assert!(metadata.len() > 0);
|
||||
|
||||
|
||||
file_path
|
||||
}
|
||||
|
||||
@@ -64,21 +64,26 @@ pub fn create_test_item(conn: &Connection) -> i64 {
|
||||
}
|
||||
|
||||
/// Test compression and decompression with an engine
|
||||
pub fn test_compression_engine(engine: &dyn crate::compression_engine::CompressionEngine, test_data: &[u8]) {
|
||||
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");
|
||||
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());
|
||||
}
|
||||
|
||||
@@ -95,5 +100,9 @@ pub fn assert_file_exists(file_path: &PathBuf) {
|
||||
|
||||
/// Assert that a file does not exist
|
||||
pub fn assert_file_not_exists(file_path: &PathBuf) {
|
||||
assert!(!file_path.exists(), "File {:?} should not exist but it does", file_path);
|
||||
assert!(
|
||||
!file_path.exists(),
|
||||
"File {:?} should not exist but it does",
|
||||
file_path
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user