reaction/tests/conf_load.rs
Baptiste Careil 1f734a516d Fix test load_conf_directory
- Fixed concurrency to 1 not to be platform dependent
- Added fields introduced by recent changes
- Used builtin str comparator that produces a diff instead of the eq
  predicate
2025-08-17 18:33:09 +02:00

80 lines
1.6 KiB
Rust

use std::error::Error;
use assert_cmd::Command;
#[test]
fn load_conf_directory() -> Result<(), Box<dyn Error>> {
let mut cmd = Command::cargo_bin("reaction")?;
cmd.args([
"test-config",
"--verbose",
"--config",
"./tests/test-conf/conf-00.d",
]);
cmd.assert().success().stdout(
r#"Loaded the configuration from the following files in the directory ./tests/test-conf/conf-00.d in this order:
part.json
part.jsonnet
part.yaml
part.yml
concurrency: 1
state_directory: .
patterns:
mypat:
regex: FLAG
ipv4mask: null
ipv6mask: null
start:
- - echo
- start
stop:
- - echo
- stop
streams:
common:
cmd:
- cat
- access.log
filters:
from_jsonnet:
regex:
- ^<mypat>
duplicate: extend
actions:
ban:
cmd:
- ban
- <mypat>
unban:
cmd:
- unban
- <mypat>
after: 42s
from_yaml:
regex:
- ^'<mypat>'
duplicate: extend
actions:
print:
cmd:
- echo
- <mypat>
after: 1s
"#);
Ok(())
}
#[test]
fn example_configs_are_equal() {
let outputs = ["config/example.yml", "config/example.jsonnet"]
.map(|config_path| {
let mut cmd = Command::cargo_bin("reaction").unwrap();
cmd.args(["test-config", "--config", config_path]);
cmd.assert().success().get_output().stdout.clone()
})
.map(String::from_utf8)
.map(Result::unwrap);
assert_eq!(outputs[0], outputs[1]);
}