test: add create_test_items helper for common test environment setup
This commit is contained in:
19
src/tests.rs
19
src/tests.rs
@@ -34,6 +34,25 @@ mod tests {
|
|||||||
dir.close().expect("Failed to remove temporary directory");
|
dir.close().expect("Failed to remove temporary directory");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper function to create test items with specific content and tags
|
||||||
|
fn create_test_items<F>(dir: &Path, f: F)
|
||||||
|
where
|
||||||
|
F: FnOnce(&str, &str),
|
||||||
|
{
|
||||||
|
// Set the data directory for this test
|
||||||
|
let env = format!("KEEP_DIR={} cargo run --", dir.display());
|
||||||
|
|
||||||
|
// Create test items
|
||||||
|
let input_a = "test content A";
|
||||||
|
let input_b = "test content B";
|
||||||
|
|
||||||
|
// Create first item with tag_a
|
||||||
|
f(input_a, "tag_a");
|
||||||
|
|
||||||
|
// Create second item with tag_b
|
||||||
|
f(input_b, "tag_b");
|
||||||
|
}
|
||||||
|
|
||||||
// Helper function to check if a file exists in the data directory
|
// Helper function to check if a file exists in the data directory
|
||||||
fn file_exists(data_dir: &Path, id: i64) -> bool {
|
fn file_exists(data_dir: &Path, id: i64) -> bool {
|
||||||
let path = data_dir.join(id.to_string());
|
let path = data_dir.join(id.to_string());
|
||||||
|
|||||||
Reference in New Issue
Block a user