Document and expand test coverage of config file feature

This commit is contained in:
2026-04-04 07:46:28 +02:00
parent db60fb9ddb
commit 8958f79ece
3 changed files with 30 additions and 5 deletions

View File

@@ -3,12 +3,18 @@ use std::process::Command;
use tempfile::TempDir;
fn sandbox(extra_args: &[&str]) -> Command {
fn sandbox_withconfig(extra_args: &[&str]) -> Command {
let mut cmd = Command::new(env!("CARGO_BIN_EXE_agent-sandbox"));
cmd.args(extra_args);
cmd
}
fn sandbox(extra_args: &[&str]) -> Command {
let mut cmd = sandbox_withconfig(&["--no-config"]);
cmd.args(extra_args);
cmd
}
fn write_config(dir: &TempDir, content: &str) -> String {
let path = dir.path().join("config.toml");
fs::write(&path, content).expect("failed to write config");
@@ -547,7 +553,7 @@ fn rw_missing_path_errors() {
#[test]
fn config_missing_file_errors() {
let output = sandbox(&["--config", "/nonexistent/config.toml"])
let output = sandbox_withconfig(&["--config", "/nonexistent/config.toml"])
.args(["--", "true"])
.output()
.expect("failed to execute");
@@ -565,7 +571,7 @@ fn config_invalid_toml_errors() {
let dir = TempDir::new().unwrap();
let cfg = write_config(&dir, "not valid {{{{ toml");
let output = sandbox(&["--config", &cfg])
let output = sandbox_withconfig(&["--config", &cfg])
.args(["--", "true"])
.output()
.expect("failed to execute");
@@ -583,7 +589,7 @@ fn config_unknown_key_errors() {
let dir = TempDir::new().unwrap();
let cfg = write_config(&dir, "hardened = true\nbogus = \"nope\"\n");
let output = sandbox(&["--config", &cfg])
let output = sandbox_withconfig(&["--config", &cfg])
.args(["--", "true"])
.output()
.expect("failed to execute");