refactor: simplify test_list_items using create_test_items helper
This commit is contained in:
44
src/tests.rs
44
src/tests.rs
@@ -188,32 +188,24 @@ mod tests {
|
||||
#[test]
|
||||
fn test_list_items() {
|
||||
with_temp_env(|data_dir| {
|
||||
// Set the data directory for this test
|
||||
// Create test items with the common environment setup
|
||||
create_test_items(data_dir, |input, tag| {
|
||||
// Set the data directory for this test
|
||||
let env = format!("KEEP_DIR={} cargo run --", data_dir.display());
|
||||
|
||||
// Create a command that pipes input to keep with the specified environment
|
||||
let cmd = format!("echo {} | {} {}", input, env, tag);
|
||||
let output = run_sh(cmd.as_str());
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"Command failed: {} RC={}",
|
||||
cmd,
|
||||
output.status
|
||||
);
|
||||
});
|
||||
|
||||
let env = format!("KEEP_DIR={} cargo run --", data_dir.display());
|
||||
|
||||
// Save an item with some content
|
||||
let input_a = "test content A";
|
||||
let input_b = "test content B";
|
||||
|
||||
// Create a command that pipes input to keep with the specified environment
|
||||
let cmd = format!("echo {} A | {} tag tag_a", input_a, env);
|
||||
let output = run_sh(cmd.as_str());
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"Command failed: {} RC={}",
|
||||
cmd,
|
||||
output.status
|
||||
);
|
||||
|
||||
let cmd = format!("echo {} | {} tag tag_b", input_b, env);
|
||||
let output = run_sh(cmd.as_str());
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"Command failed: {} RC={}",
|
||||
cmd,
|
||||
output.status
|
||||
);
|
||||
|
||||
let cmd = format!("{} --list", env);
|
||||
let output = run_sh(cmd.as_str());
|
||||
assert!(
|
||||
@@ -227,7 +219,7 @@ mod tests {
|
||||
let output = run_sh(cmd.as_str());
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"Command failed with status: {} RC={}",
|
||||
"Command failed: {} RC={}",
|
||||
cmd,
|
||||
output.status
|
||||
);
|
||||
@@ -236,7 +228,7 @@ mod tests {
|
||||
let output = run_sh(cmd.as_str());
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"Command failed with status: {} RC={}",
|
||||
"Command failed: {} RC={}",
|
||||
cmd,
|
||||
output.status
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user