20260914 完善OSS日志与daemon部署
This commit is contained in:
70
tests/logging_contract.rs
Normal file
70
tests/logging_contract.rs
Normal file
@@ -0,0 +1,70 @@
|
||||
use std::process::Command;
|
||||
|
||||
#[test]
|
||||
fn default_format_is_human_readable_text() {
|
||||
let result = Command::new(env!("CARGO_BIN_EXE_panda-rpki"))
|
||||
.env_remove("PANDA_RPKI_LOG_FORMAT")
|
||||
.env_remove("PANDA_RPKI_LOG_LEVEL")
|
||||
.args(["validate"])
|
||||
.output()
|
||||
.unwrap();
|
||||
let diagnostic = String::from_utf8(result.stderr).unwrap();
|
||||
assert_eq!(result.status.code(), Some(2));
|
||||
assert!(diagnostic.contains("ERROR Command failed"));
|
||||
assert!(!diagnostic.contains("command_failed"));
|
||||
let call_line = include_str!("../src/main.rs")
|
||||
.lines()
|
||||
.position(|line| line.contains("panda_rpki::logging::emit("))
|
||||
.unwrap()
|
||||
+ 1;
|
||||
assert!(diagnostic.ends_with(&format!("[src/main.rs:{call_line}]\n")));
|
||||
assert!(result.stdout.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_progress_interval_is_rejected_without_outputs() {
|
||||
for value in ["-1", "wrong", "18446744073709551616"] {
|
||||
let result = Command::new(env!("CARGO_BIN_EXE_panda-rpki"))
|
||||
.args(["validate", "--log-progress-interval-secs", value])
|
||||
.output()
|
||||
.unwrap();
|
||||
assert_eq!(result.status.code(), Some(2));
|
||||
assert!(result.stdout.is_empty());
|
||||
assert!(String::from_utf8_lossy(&result.stderr).contains("log-progress-interval-secs"));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn progress_cli_overrides_invalid_environment() {
|
||||
let result = Command::new(env!("CARGO_BIN_EXE_panda-rpki"))
|
||||
.env("PANDA_RPKI_LOG_PROGRESS_INTERVAL_SECS", "invalid")
|
||||
.args([
|
||||
"validate",
|
||||
"--log-progress-interval-secs",
|
||||
"0",
|
||||
"--log-format",
|
||||
"json",
|
||||
])
|
||||
.output()
|
||||
.unwrap();
|
||||
let record: serde_json::Value = serde_json::from_slice(&result.stderr).unwrap();
|
||||
let call_line = include_str!("../src/main.rs")
|
||||
.lines()
|
||||
.position(|line| line.contains("panda_rpki::logging::emit("))
|
||||
.unwrap()
|
||||
+ 1;
|
||||
assert_eq!(record["source"]["file"], "src/main.rs");
|
||||
assert_eq!(record["source"]["line"], call_line);
|
||||
assert!(
|
||||
record["fields"]["error"]
|
||||
.as_str()
|
||||
.unwrap()
|
||||
.contains("--tal")
|
||||
);
|
||||
assert!(
|
||||
!record["fields"]["error"]
|
||||
.as_str()
|
||||
.unwrap()
|
||||
.contains("progress")
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user