Ugh
This commit is contained in:
@@ -6,7 +6,7 @@ mod tests {
|
||||
fn test_is_binary_text() {
|
||||
let text_data = b"Hello, World! This is plain text.\nWith newlines and spaces.";
|
||||
let result = is_binary(text_data);
|
||||
|
||||
|
||||
// Text data should not be detected as binary
|
||||
assert!(!result);
|
||||
}
|
||||
@@ -15,7 +15,7 @@ mod tests {
|
||||
fn test_is_binary_binary() {
|
||||
let binary_data = b"\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09";
|
||||
let result = is_binary(binary_data);
|
||||
|
||||
|
||||
// Binary data should be detected as binary
|
||||
assert!(result);
|
||||
}
|
||||
@@ -24,7 +24,7 @@ mod tests {
|
||||
fn test_is_binary_png_signature() {
|
||||
let png_data = b"\x89\x50\x4E\x47\x0D\x0A\x1A\x0A";
|
||||
let result = is_binary(png_data);
|
||||
|
||||
|
||||
// PNG signature should be detected as binary
|
||||
assert!(result);
|
||||
}
|
||||
@@ -33,7 +33,7 @@ mod tests {
|
||||
fn test_is_binary_empty() {
|
||||
let empty_data = b"";
|
||||
let result = is_binary(empty_data);
|
||||
|
||||
|
||||
// Empty data should not be detected as binary
|
||||
assert!(!result);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
mod tests {
|
||||
// TODO: Add tests for common status functionality once implemented
|
||||
// This would test functions related to status checking in the common module
|
||||
|
||||
|
||||
#[test]
|
||||
fn test_status_placeholder() {
|
||||
// Placeholder test - to be implemented when status functionality is added
|
||||
|
||||
@@ -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