20260914 强制 TOML 配置并完善 TA 刷新与 daemon
This commit is contained in:
@@ -1,15 +1,12 @@
|
||||
use std::process::Command;
|
||||
|
||||
fn command() -> Command {
|
||||
let mut cmd = Command::new(env!("CARGO_BIN_EXE_panda-rpki"));
|
||||
cmd.env_remove("PANDA_RPKI_LOG_LEVEL")
|
||||
.env_remove("PANDA_RPKI_LOG_FORMAT");
|
||||
cmd
|
||||
Command::new(env!("CARGO_BIN_EXE_panda-rpki"))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn help_is_successful_and_goes_to_stdout() {
|
||||
for args in [vec![], vec!["--help"], vec!["-h"]] {
|
||||
fn top_level_help_and_version_are_successful() {
|
||||
for args in [vec!["--help"], vec!["-h"], vec!["--version"], vec!["-V"]] {
|
||||
let result = command().args(args).output().unwrap();
|
||||
assert!(result.status.success());
|
||||
assert!(String::from_utf8_lossy(&result.stdout).contains("panda-rpki"));
|
||||
@@ -18,20 +15,26 @@ fn help_is_successful_and_goes_to_stdout() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_command_returns_two_without_stdout() {
|
||||
let result = command().arg("not-a-command").output().unwrap();
|
||||
assert_eq!(result.status.code(), Some(2));
|
||||
assert!(result.stdout.is_empty());
|
||||
assert!(String::from_utf8_lossy(&result.stderr).contains("unknown command"));
|
||||
fn subcommand_help_does_not_read_a_config() {
|
||||
for mode in ["validate", "daemon"] {
|
||||
let result = command()
|
||||
.args([mode, "--help", "--config", "missing.toml"])
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(result.status.success());
|
||||
assert!(String::from_utf8_lossy(&result.stdout).contains("--config FILE"));
|
||||
assert!(result.stderr.is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn malformed_validation_arguments_do_not_create_outputs() {
|
||||
fn missing_config_and_removed_options_are_rejected_without_outputs() {
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
for args in [
|
||||
vec!["validate", "--out", "output"],
|
||||
vec!["validate", "--unknown", "value"],
|
||||
vec!["validate", "--out"],
|
||||
vec!["validate"],
|
||||
vec!["validate", "--tal", "input.tal"],
|
||||
vec!["daemon", "--state-root", "data"],
|
||||
vec!["validate", "--config", "missing.toml", "--unknown"],
|
||||
] {
|
||||
let result = command()
|
||||
.current_dir(directory.path())
|
||||
@@ -40,25 +43,51 @@ fn malformed_validation_arguments_do_not_create_outputs() {
|
||||
.unwrap();
|
||||
assert_eq!(result.status.code(), Some(2));
|
||||
assert!(result.stdout.is_empty());
|
||||
assert!(String::from_utf8_lossy(&result.stderr).contains("panda-rpki:"));
|
||||
assert_eq!(std::fs::read_dir(directory.path()).unwrap().count(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_daemon_state_root_fails_without_creating_state() {
|
||||
fn check_config_is_read_only_for_invalid_inputs() {
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
std::fs::write(
|
||||
directory.path().join("validate.toml"),
|
||||
r#"
|
||||
config-version = 1
|
||||
mode = "validate"
|
||||
out = "output"
|
||||
|
||||
[[anchors]]
|
||||
id = "missing"
|
||||
tal = "missing.tal"
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let result = command()
|
||||
.current_dir(directory.path())
|
||||
.args([
|
||||
"daemon",
|
||||
"--",
|
||||
"--tal",
|
||||
"missing.tal",
|
||||
"--ta",
|
||||
"missing.cer",
|
||||
])
|
||||
.args(["validate", "--config", "validate.toml", "--check-config"])
|
||||
.output()
|
||||
.unwrap();
|
||||
assert_eq!(result.status.code(), Some(2));
|
||||
assert_eq!(std::fs::read_dir(directory.path()).unwrap().count(), 0);
|
||||
assert!(!directory.path().join("output").exists());
|
||||
|
||||
let result = command()
|
||||
.current_dir(directory.path())
|
||||
.args(["validate", "--config", "validate.toml", "--print-config"])
|
||||
.output()
|
||||
.unwrap();
|
||||
assert_eq!(result.status.code(), Some(2));
|
||||
assert!(!directory.path().join("output").exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn config_mode_and_mutually_exclusive_inspection_flags_are_rejected() {
|
||||
let result = command()
|
||||
.args(["validate", "--check-config", "--print-config"])
|
||||
.output()
|
||||
.unwrap();
|
||||
assert_eq!(result.status.code(), Some(2));
|
||||
assert!(String::from_utf8_lossy(&result.stderr).contains("mutually exclusive"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user