feat: add populated test database and directory helper functions
Co-authored-by: aider (openai/andrew/openrouter/qwen/qwen3-coder) <aider@aider.chat>
This commit is contained in:
@@ -144,3 +144,42 @@ pub fn assert_file_exists(file_path: &PathBuf) {
|
||||
pub fn assert_file_not_exists(file_path: &PathBuf) {
|
||||
assert!(!file_path.exists(), "File {:?} should not exist but it does", file_path);
|
||||
}
|
||||
|
||||
/// Create a temporary database and populate it with sample data for testing
|
||||
pub fn create_populated_test_db() -> (TempDir, Connection, PathBuf) {
|
||||
let (temp_dir, conn, db_path) = create_temp_db();
|
||||
|
||||
// Insert some sample items
|
||||
for i in 1..=5 {
|
||||
let item = crate::db::Item {
|
||||
id: None,
|
||||
ts: chrono::Utc::now(),
|
||||
size: Some(i * 100),
|
||||
compression: if i % 2 == 0 {
|
||||
crate::compression_engine::CompressionType::LZ4.to_string()
|
||||
} else {
|
||||
crate::compression_engine::CompressionType::GZip.to_string()
|
||||
},
|
||||
};
|
||||
db::insert_item(&conn, item).expect("Failed to insert item");
|
||||
}
|
||||
|
||||
(temp_dir, conn, db_path)
|
||||
}
|
||||
|
||||
/// Assert that a directory exists and is actually a directory
|
||||
pub fn assert_directory_exists(dir_path: &PathBuf) {
|
||||
assert!(dir_path.exists(), "Directory {:?} does not exist", dir_path);
|
||||
assert!(dir_path.is_dir(), "Path {:?} exists but is not a directory", dir_path);
|
||||
}
|
||||
|
||||
/// Create a nested directory structure for testing
|
||||
pub fn create_nested_temp_dir_structure(dir: &TempDir) -> (PathBuf, PathBuf, PathBuf) {
|
||||
let level1 = dir.path().join("level1");
|
||||
let level2 = level1.join("level2");
|
||||
let level3 = level2.join("level3");
|
||||
|
||||
std::fs::create_dir_all(&level3).expect("Failed to create nested directory structure");
|
||||
|
||||
(level1, level2, level3)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user