fix: resolve test errors, add tempfile, fix command args
This commit is contained in:
@@ -33,3 +33,6 @@ flate2 = { version = "1.0.27", features = ["zlib-ng-compat"] }
|
|||||||
regex = "1.9.5"
|
regex = "1.9.5"
|
||||||
nix = "0.26.2"
|
nix = "0.26.2"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
tempfile = "3.3.0"
|
||||||
|
|
||||||
|
|||||||
90
src/tests.rs
90
src/tests.rs
@@ -3,12 +3,14 @@ mod tests {
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::Command;
|
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
|
// Helper function to run the keep command with given arguments
|
||||||
fn run_keep(args: &[&str]) -> std::process::Output {
|
fn run_keep(args: &[&str]) -> std::process::Output {
|
||||||
let output = Command::new("cargo")
|
let output = Command::new("cargo")
|
||||||
.args(["run", "--", args])
|
.args(["run", "--",])
|
||||||
|
.args(args)
|
||||||
.output()
|
.output()
|
||||||
.expect("Failed to execute command");
|
.expect("Failed to execute command");
|
||||||
output
|
output
|
||||||
@@ -54,24 +56,23 @@ mod tests {
|
|||||||
// Save an item with some content
|
// Save an item with some content
|
||||||
let input = "test content";
|
let input = "test content";
|
||||||
// Create a command that pipes input to keep with the specified environment
|
// Create a command that pipes input to keep with the specified environment
|
||||||
let cmd = format!("echo {} | {}", input, env);
|
let mut cmd = Command::new("sh");
|
||||||
let mut child = Command::new("sh")
|
cmd.arg("-c")
|
||||||
.arg("-c")
|
.arg(format!("echo {} | {}", input, env));
|
||||||
.arg(cmd)
|
|
||||||
.spawn()
|
|
||||||
.expect("Failed to spawn process");
|
|
||||||
|
|
||||||
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
|
// Verify the item was saved
|
||||||
let items: Vec<String> = Command::new("sh")
|
let output = Command::new("sh")
|
||||||
.arg("-c")
|
.arg("-c")
|
||||||
.arg(format!("{} cargo run -- --list", env))
|
.arg(format!("{} cargo run -- --list", env))
|
||||||
.output()
|
.output()
|
||||||
.expect("Failed to execute command")
|
.expect("Failed to execute command");
|
||||||
.stdout;
|
|
||||||
|
|
||||||
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
|
// Save an item with some content
|
||||||
let input = "test content";
|
let input = "test content";
|
||||||
// Create a command that pipes input to keep with the specified environment
|
// Create a command that pipes input to keep with the specified environment
|
||||||
let cmd = format!("echo {} | {}", input, env);
|
let mut cmd = Command::new("sh");
|
||||||
let mut child = Command::new("sh")
|
cmd.arg("-c")
|
||||||
.arg("-c")
|
.arg(format!("echo {} | {}", input, env));
|
||||||
.arg(cmd)
|
|
||||||
.spawn()
|
|
||||||
.expect("Failed to spawn process");
|
|
||||||
|
|
||||||
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
|
// Get the item and verify the content
|
||||||
let output = Command::new("sh")
|
let output = Command::new("sh")
|
||||||
@@ -191,15 +192,15 @@ mod tests {
|
|||||||
// Save an item with some content and metadata
|
// Save an item with some content and metadata
|
||||||
let input = "test content";
|
let input = "test content";
|
||||||
// Create a command that pipes input to keep with the specified environment and metadata
|
// Create a command that pipes input to keep with the specified environment and metadata
|
||||||
let cmd = format!("echo {} | {}", input, env);
|
let mut cmd = Command::new("sh");
|
||||||
let mut child = Command::new("sh")
|
cmd.arg("-c")
|
||||||
.arg("-c")
|
.arg(format!("echo {} | {}", input, env))
|
||||||
.arg(cmd)
|
.arg("cargo run -- --save --meta key=value");
|
||||||
.arg("cargo run -- --save --meta key=value")
|
|
||||||
.spawn()
|
|
||||||
.expect("Failed to spawn process");
|
|
||||||
|
|
||||||
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
|
// Get the item ID
|
||||||
let list_output = Command::new("sh")
|
let list_output = Command::new("sh")
|
||||||
@@ -231,15 +232,15 @@ mod tests {
|
|||||||
// Save an item with some content and tags
|
// Save an item with some content and tags
|
||||||
let input = "test content";
|
let input = "test content";
|
||||||
// Create a command that pipes input to keep with the specified environment and tags
|
// Create a command that pipes input to keep with the specified environment and tags
|
||||||
let cmd = format!("echo {} | {}", input, env);
|
let mut cmd = Command::new("sh");
|
||||||
let mut child = Command::new("sh")
|
cmd.arg("-c")
|
||||||
.arg("-c")
|
.arg(format!("echo {} | {}", input, env))
|
||||||
.arg(cmd)
|
.arg("cargo run -- --save --tag tag1 --tag tag2");
|
||||||
.arg("cargo run -- --save --tag tag1 --tag tag2")
|
|
||||||
.spawn()
|
|
||||||
.expect("Failed to spawn process");
|
|
||||||
|
|
||||||
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
|
// List items with a specific tag
|
||||||
let output = Command::new("sh")
|
let output = Command::new("sh")
|
||||||
@@ -262,15 +263,15 @@ mod tests {
|
|||||||
// Save an item with some content and compression
|
// Save an item with some content and compression
|
||||||
let input = "test content";
|
let input = "test content";
|
||||||
// Create a command that pipes input to keep with the specified environment and compression
|
// Create a command that pipes input to keep with the specified environment and compression
|
||||||
let cmd = format!("echo {} | {}", input, env);
|
let mut cmd = Command::new("sh");
|
||||||
let mut child = Command::new("sh")
|
cmd.arg("-c")
|
||||||
.arg("-c")
|
.arg(format!("echo {} | {}", input, env))
|
||||||
.arg(cmd)
|
.arg("cargo run -- --save --compression gzip");
|
||||||
.arg("cargo run -- --save --compression gzip")
|
|
||||||
.spawn()
|
|
||||||
.expect("Failed to spawn process");
|
|
||||||
|
|
||||||
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
|
// Get the item ID
|
||||||
let list_output = Command::new("sh")
|
let list_output = Command::new("sh")
|
||||||
@@ -292,4 +293,3 @@ mod tests {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mod tests;
|
|
||||||
|
|||||||
Reference in New Issue
Block a user