mirror of
https://framagit.org/ppom/reaction
synced 2026-03-14 12:45:47 +01:00
Duplicate: Fix tests, more tests
This commit is contained in:
parent
d9842c2340
commit
270a1a9bdf
3 changed files with 41 additions and 37 deletions
|
|
@ -11,7 +11,7 @@ use tokio::sync::Semaphore;
|
|||
|
||||
use super::{state::filter_ordered_times_db_name, FilterManager, React};
|
||||
use crate::{
|
||||
concepts::{Action, Filter, MatchTime, Pattern, Patterns, Time},
|
||||
concepts::{Action, Filter, Pattern, Patterns, Time},
|
||||
daemon::shutdown::ShutdownController,
|
||||
tests::TempDatabase,
|
||||
};
|
||||
|
|
@ -173,13 +173,7 @@ async fn three_matches_then_action_then_delayed_action() {
|
|||
);
|
||||
assert_eq!(
|
||||
state.triggers.tree(),
|
||||
&BTreeMap::from([(
|
||||
MatchTime {
|
||||
m: one.clone(),
|
||||
t: now2s
|
||||
},
|
||||
1
|
||||
)]),
|
||||
&BTreeMap::from([(one.clone(), BTreeMap::from([(now2s, 1)]))]),
|
||||
// 1 and not 2 because the decrement_trigger() doesn't wait for the semaphore
|
||||
"triggers now contain the triggered match with 1 action left"
|
||||
);
|
||||
|
|
@ -191,13 +185,7 @@ async fn three_matches_then_action_then_delayed_action() {
|
|||
// Check first action
|
||||
assert_eq!(
|
||||
bed.manager.state.lock().unwrap().triggers.tree(),
|
||||
&BTreeMap::from([(
|
||||
MatchTime {
|
||||
m: one.clone(),
|
||||
t: now2s
|
||||
},
|
||||
1
|
||||
)]),
|
||||
&BTreeMap::from([(one.clone(), BTreeMap::from([(now2s, 1)]))]),
|
||||
"triggers still contain the triggered match with 1 action left"
|
||||
);
|
||||
assert_eq!(
|
||||
|
|
@ -302,13 +290,7 @@ async fn one_match_one_delayed_action() {
|
|||
assert!(state.ordered_times.is_empty(), "ordered_times stay empty");
|
||||
assert_eq!(
|
||||
state.triggers.tree(),
|
||||
&BTreeMap::from([(
|
||||
MatchTime {
|
||||
m: one.clone(),
|
||||
t: now,
|
||||
},
|
||||
1
|
||||
)]),
|
||||
&BTreeMap::from([(one.clone(), BTreeMap::from([(now, 1)]))]),
|
||||
"triggers still contain the triggered match with 1 action left"
|
||||
);
|
||||
}
|
||||
|
|
@ -497,13 +479,7 @@ async fn trigger_unmatched_pattern() {
|
|||
assert!(state.ordered_times.is_empty());
|
||||
assert_eq!(
|
||||
state.triggers.tree(),
|
||||
&BTreeMap::from([(
|
||||
MatchTime {
|
||||
m: one.clone(),
|
||||
t: now,
|
||||
},
|
||||
1
|
||||
)])
|
||||
&BTreeMap::from([(one.clone(), BTreeMap::from([(now, 1)]))]),
|
||||
);
|
||||
}
|
||||
assert_eq!(
|
||||
|
|
@ -578,13 +554,7 @@ async fn trigger_matched_pattern() {
|
|||
assert!(state.ordered_times.is_empty());
|
||||
assert_eq!(
|
||||
state.triggers.tree(),
|
||||
&BTreeMap::from([(
|
||||
MatchTime {
|
||||
m: one.clone(),
|
||||
t: now,
|
||||
},
|
||||
1
|
||||
)])
|
||||
&BTreeMap::from([(one.clone(), BTreeMap::from([(now, 1)]))]),
|
||||
);
|
||||
}
|
||||
assert_eq!(
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ fn string_to_time(val: &str) -> Result<Time, String> {
|
|||
|
||||
/// Tries to convert a [`Value`] into a [`Time`]
|
||||
pub fn to_time(val: &Value) -> Result<Time, String> {
|
||||
Ok(string_to_time(val.as_str().ok_or("not a number")?)?)
|
||||
Ok(string_to_time(val.as_str().ok_or("not a datetime")?)?)
|
||||
}
|
||||
|
||||
/// Tries to convert a [`Value`] into a [`Match`]
|
||||
|
|
@ -200,4 +200,37 @@ mod tests {
|
|||
assert!(to_timeset(&(8.into())).is_err());
|
||||
assert!(to_timeset(&(None::<String>.into())).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_to_timemap() {
|
||||
let time1 = "2025-07-10T12:35:00.000+02:00";
|
||||
let time1_t = DateTime::parse_from_rfc3339(time1)
|
||||
.unwrap()
|
||||
.with_timezone(&Local);
|
||||
let time2 = "2026-08-11T12:36:01.000+02:00";
|
||||
let time2_t = DateTime::parse_from_rfc3339(time2)
|
||||
.unwrap()
|
||||
.with_timezone(&Local);
|
||||
|
||||
assert_eq!(
|
||||
to_timemap(&Value::from_iter([(time2, 1)])),
|
||||
Ok(BTreeMap::from([(time2_t, 1)]))
|
||||
);
|
||||
assert_eq!(
|
||||
to_timemap(&Value::from_iter([(time1, 4), (time2, 0)])),
|
||||
Ok(BTreeMap::from([(time1_t, 4), (time2_t, 0)]))
|
||||
);
|
||||
|
||||
assert!(to_timemap(&Value::from_iter([("1", time2)])).is_err());
|
||||
assert!(to_timemap(&Value::from_iter([(time2, time2)])).is_err());
|
||||
assert!(to_timemap(&Value::from_iter([(time2)])).is_err());
|
||||
assert!(to_timemap(&Value::from_iter([(1)])).is_err());
|
||||
|
||||
assert!(to_timemap(&(["1970-01-01T01:20:34.567+01:00"].into())).is_err());
|
||||
assert!(to_timemap(&([""].into())).is_err());
|
||||
assert!(to_timemap(&(["ploup"].into())).is_err());
|
||||
assert!(to_timemap(&(true.into())).is_err());
|
||||
assert!(to_timemap(&(8.into())).is_err());
|
||||
assert!(to_timemap(&(None::<String>.into())).is_err());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ fn config_with_cmd(config_path: &str, cmd: &str) {
|
|||
regex: ['here is <num>'],
|
||||
retry: 2,
|
||||
retryperiod: '2s',
|
||||
duplicate: 'rerun',
|
||||
actions: {
|
||||
// Don't mix code and data at home!
|
||||
// You may permit arbitrary execution from vilains,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue