mirror of
https://framagit.org/ppom/reaction
synced 2026-03-14 20:55:47 +01:00
Fix some triggers no longer triggering after being loaded from db
This commit is contained in:
parent
278baaa3e6
commit
c6e4af96cd
3 changed files with 100 additions and 1 deletions
|
|
@ -257,7 +257,9 @@ impl FilterManager {
|
|||
.filter(|action| !startup || !action.oneshot)
|
||||
// skip any actions
|
||||
.skip(match actions_left {
|
||||
Some(actions_left) => self.filter.actions.len() - actions_left as usize,
|
||||
Some(actions_left) => {
|
||||
self.filter.filtered_actions_from_match(&m).len() - actions_left as usize
|
||||
}
|
||||
None => 0,
|
||||
});
|
||||
|
||||
|
|
|
|||
51
tests/persistence.rs
Normal file
51
tests/persistence.rs
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
use std::{error::Error, path::Path, time::Duration};
|
||||
|
||||
use assert_cmd::Command;
|
||||
use assert_fs::prelude::*;
|
||||
use predicates::prelude::predicate;
|
||||
|
||||
#[test]
|
||||
fn resume_action() -> Result<(), Box<dyn Error>> {
|
||||
let tmp_dir = assert_fs::TempDir::new()?;
|
||||
|
||||
tmp_dir
|
||||
.child("config.jsonnet")
|
||||
.write_file(Path::new("tests/test-conf/test-resume-action.jsonnet"))?;
|
||||
|
||||
// first run
|
||||
let mut cmd = Command::cargo_bin("reaction")?;
|
||||
cmd.args(["start", "--socket", "./s", "--config", "./config.jsonnet"]);
|
||||
cmd.current_dir(tmp_dir.path());
|
||||
cmd.timeout(Duration::from_secs(5));
|
||||
// Expected exit 1: all stream exited
|
||||
cmd.assert().code(predicate::eq(1));
|
||||
|
||||
// expect a single match from the stream command
|
||||
let expected = ["starting", "start4 10.1.0.1", "stopping"].join("\n") + "\n";
|
||||
tmp_dir.child("log").assert(&expected);
|
||||
|
||||
// second run, expect to resume action
|
||||
let mut cmd = Command::cargo_bin("reaction")?;
|
||||
cmd.args(["start", "--socket", "./s", "--config", "./config.jsonnet"]);
|
||||
cmd.current_dir(tmp_dir.path());
|
||||
cmd.timeout(Duration::from_secs(5));
|
||||
// Expected exit 1: all stream exited
|
||||
cmd.assert().code(predicate::eq(1));
|
||||
|
||||
let expected = [
|
||||
"starting",
|
||||
"start4 10.1.0.1", // from the stream command
|
||||
"stopping",
|
||||
"starting",
|
||||
"start4 10.1.0.1", // previous action loaded from db
|
||||
"stop4 10.1.0.1", // previous action lapses
|
||||
"start4 10.1.0.1", // from the stream command
|
||||
"stopping",
|
||||
]
|
||||
.join("\n")
|
||||
+ "\n";
|
||||
|
||||
tmp_dir.child("log").assert(&expected);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
46
tests/test-conf/test-resume-action.jsonnet
Normal file
46
tests/test-conf/test-resume-action.jsonnet
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
{
|
||||
patterns: {
|
||||
ip: {
|
||||
type: 'ip',
|
||||
ipv6mask: 64,
|
||||
},
|
||||
},
|
||||
start: [
|
||||
['sh', '-c', 'echo starting >>./log'],
|
||||
],
|
||||
stop: [
|
||||
['sh', '-c', 'echo stopping >>./log'],
|
||||
],
|
||||
streams: {
|
||||
s1: {
|
||||
cmd: ['sh', '-c', 'sleep 2; echo T 10.1.0.1; sleep 0.2; echo T 10.1.0.1; sleep 0.8'],
|
||||
filters: {
|
||||
f1: {
|
||||
regex: ['T <ip>'],
|
||||
actions: {
|
||||
log_start4: {
|
||||
ipv4only: true,
|
||||
cmd: ['sh', '-c', 'echo start4 <ip> >>./log'],
|
||||
},
|
||||
log_start6: {
|
||||
ipv6only: true,
|
||||
cmd: ['sh', '-c', 'echo start6 <ip> >>./log'],
|
||||
},
|
||||
log_stop4: {
|
||||
ipv4only: true,
|
||||
onexit: false,
|
||||
after: '2s',
|
||||
cmd: ['sh', '-c', 'echo stop4 <ip> >> ./log'],
|
||||
},
|
||||
log_stop6: {
|
||||
ipv6only: true,
|
||||
onexit: false,
|
||||
after: '2s',
|
||||
cmd: ['sh', '-c', 'echo stop6 <ip> >> ./log'],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue