fix: resolve test errors, add tempfile, fix command args

This commit is contained in:
Andrew Phillips (aider)
2025-05-12 11:49:49 -03:00
parent 4b8e082179
commit 850f5fb80a
2 changed files with 48 additions and 45 deletions

View File

@@ -3,12 +3,14 @@ mod tests {
use std::fs;
use std::path::Path;
use std::process::Command;
use tempfile::tempdir;
use std::ffi::OsStr;
use std::process::Stdio;
// Helper function to run the keep command with given arguments
fn run_keep(args: &[&str]) -> std::process::Output {
let output = Command::new("cargo")
.args(["run", "--", args])
.args(["run", "--",])
.args(args)
.output()
.expect("Failed to execute command");
output
@@ -54,24 +56,23 @@ mod tests {
// Save an item with some content
let input = "test content";
// Create a command that pipes input to keep with the specified environment
let cmd = format!("echo {} | {}", input, env);
let mut child = Command::new("sh")
.arg("-c")
.arg(cmd)
.spawn()
.expect("Failed to spawn process");
let mut cmd = Command::new("sh");
cmd.arg("-c")
.arg(format!("echo {} | {}", input, env));
child.wait().expect("Failed to wait for child process");
cmd.spawn()
.expect("Failed to spawn process")
.wait()
.expect("Failed to wait for child process");
// Verify the item was saved
let items: Vec<String> = Command::new("sh")
let output = Command::new("sh")
.arg("-c")
.arg(format!("{} cargo run -- --list", env))
.output()
.expect("Failed to execute command")
.stdout;
.expect("Failed to execute command");
assert!(String::from_utf8_lossy(&items).contains(input));
assert!(String::from_utf8_lossy(&output.stdout).contains(input));
});
}
@@ -85,14 +86,14 @@ mod tests {
// Save an item with some content
let input = "test content";
// Create a command that pipes input to keep with the specified environment
let cmd = format!("echo {} | {}", input, env);
let mut child = Command::new("sh")
.arg("-c")
.arg(cmd)
.spawn()
.expect("Failed to spawn process");
let mut cmd = Command::new("sh");
cmd.arg("-c")
.arg(format!("echo {} | {}", input, env));
child.wait().expect("Failed to wait for child process");
cmd.spawn()
.expect("Failed to spawn process")
.wait()
.expect("Failed to wait for child process");
// Get the item and verify the content
let output = Command::new("sh")
@@ -191,15 +192,15 @@ mod tests {
// Save an item with some content and metadata
let input = "test content";
// Create a command that pipes input to keep with the specified environment and metadata
let cmd = format!("echo {} | {}", input, env);
let mut child = Command::new("sh")
.arg("-c")
.arg(cmd)
.arg("cargo run -- --save --meta key=value")
.spawn()
.expect("Failed to spawn process");
let mut cmd = Command::new("sh");
cmd.arg("-c")
.arg(format!("echo {} | {}", input, env))
.arg("cargo run -- --save --meta key=value");
child.wait().expect("Failed to wait for child process");
cmd.spawn()
.expect("Failed to spawn process")
.wait()
.expect("Failed to wait for child process");
// Get the item ID
let list_output = Command::new("sh")
@@ -231,15 +232,15 @@ mod tests {
// Save an item with some content and tags
let input = "test content";
// Create a command that pipes input to keep with the specified environment and tags
let cmd = format!("echo {} | {}", input, env);
let mut child = Command::new("sh")
.arg("-c")
.arg(cmd)
.arg("cargo run -- --save --tag tag1 --tag tag2")
.spawn()
.expect("Failed to spawn process");
let mut cmd = Command::new("sh");
cmd.arg("-c")
.arg(format!("echo {} | {}", input, env))
.arg("cargo run -- --save --tag tag1 --tag tag2");
child.wait().expect("Failed to wait for child process");
cmd.spawn()
.expect("Failed to spawn process")
.wait()
.expect("Failed to wait for child process");
// List items with a specific tag
let output = Command::new("sh")
@@ -262,15 +263,15 @@ mod tests {
// Save an item with some content and compression
let input = "test content";
// Create a command that pipes input to keep with the specified environment and compression
let cmd = format!("echo {} | {}", input, env);
let mut child = Command::new("sh")
.arg("-c")
.arg(cmd)
.arg("cargo run -- --save --compression gzip")
.spawn()
.expect("Failed to spawn process");
let mut cmd = Command::new("sh");
cmd.arg("-c")
.arg(format!("echo {} | {}", input, env))
.arg("cargo run -- --save --compression gzip");
child.wait().expect("Failed to wait for child process");
cmd.spawn()
.expect("Failed to spawn process")
.wait()
.expect("Failed to wait for child process");
// Get the item ID
let list_output = Command::new("sh")
@@ -292,4 +293,3 @@ mod tests {
});
}
}
mod tests;