From f4b8572e94e46dde49f18236da995fda2acebe4e Mon Sep 17 00:00:00 2001 From: ppom Date: Wed, 26 Feb 2025 12:00:00 +0100 Subject: [PATCH] run clippy on test target --- src/concepts/action.rs | 1 - src/concepts/filter.rs | 3 +-- src/concepts/pattern.rs | 1 - src/daemon/filter.rs | 13 ++++--------- src/daemon/filter/tests.rs | 9 +++++---- src/daemon/sledext.rs | 2 +- src/lib.rs | 3 +++ src/tests.rs | 5 ++--- 8 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/concepts/action.rs b/src/concepts/action.rs index dc6d62a..d11462c 100644 --- a/src/concepts/action.rs +++ b/src/concepts/action.rs @@ -183,7 +183,6 @@ impl Action { } } -#[allow(clippy::unwrap_used)] #[cfg(test)] pub mod tests { diff --git a/src/concepts/filter.rs b/src/concepts/filter.rs index 01cdaf7..57d4c67 100644 --- a/src/concepts/filter.rs +++ b/src/concepts/filter.rs @@ -251,7 +251,7 @@ impl Filter { retry_period: retry_period.map(|s| s.into()), ..Default::default() }; - filter.setup(&stream_name, &name, config_patterns).unwrap(); + filter.setup(stream_name, name, config_patterns).unwrap(); filter } @@ -276,7 +276,6 @@ impl Filter { } } -#[allow(clippy::unwrap_used)] #[cfg(test)] pub mod tests { use crate::concepts::action::tests::{ok_action, ok_action_with_after}; diff --git a/src/concepts/pattern.rs b/src/concepts/pattern.rs index c248258..38aae5b 100644 --- a/src/concepts/pattern.rs +++ b/src/concepts/pattern.rs @@ -135,7 +135,6 @@ impl Pattern { } } -#[allow(clippy::unwrap_used)] #[cfg(test)] pub mod tests { diff --git a/src/daemon/filter.rs b/src/daemon/filter.rs index 2b0f766..3605309 100644 --- a/src/daemon/filter.rs +++ b/src/daemon/filter.rs @@ -1,3 +1,6 @@ +#[cfg(test)] +mod tests; + use std::{ collections::{BTreeMap, BTreeSet}, process::Stdio, @@ -278,11 +281,7 @@ impl FilterManager { .fetch_and_update(&m, |set| { let mut set = set.unwrap(); set.remove(&t); - if set.is_empty() { - None - } else { - Some(set) - } + (!set.is_empty()).then_some(set) }) .unwrap(); } @@ -346,7 +345,3 @@ impl FilterManager { }); } } - -#[allow(clippy::unwrap_used)] -#[cfg(test)] -mod tests; diff --git a/src/daemon/filter/tests.rs b/src/daemon/filter/tests.rs index b3f7d29..7ba1879 100644 --- a/src/daemon/filter/tests.rs +++ b/src/daemon/filter/tests.rs @@ -16,6 +16,7 @@ use crate::{ tests::TempDb, }; +#[allow(clippy::type_complexity)] fn open_trees( db: &TempDb, filter: &Filter, @@ -51,7 +52,7 @@ impl TestBed { } fn part2(self, filter: &'static Filter, now: Time, db: Option) -> TestBed2 { - let db = db.unwrap_or_else(|| TempDb::new()); + let db = db.unwrap_or_default(); let controller = ShutdownController::new(); let semaphore = Arc::new(Semaphore::new(1)); TestBed2 { @@ -62,7 +63,7 @@ impl TestBed { ordered_times: db.open_filter_ordered_times_tree(filter).unwrap(), triggers: db.open_filter_triggers_tree(filter).unwrap(), manager: FilterManager::new( - &filter, + filter, Some(semaphore.clone()), controller.token(), &db, @@ -362,7 +363,7 @@ async fn one_db_match_one_runtime_match_one_action() { &bed.az_patterns, ); - let db = TempDb::new(); + let db = TempDb::default(); let (matches, ordered_times, _) = open_trees(&db, filter); // Pre-add match @@ -421,7 +422,7 @@ async fn one_outdated_db_match() { &bed.az_patterns, ); - let db = TempDb::new(); + let db = TempDb::default(); let (matches, ordered_times, _) = open_trees(&db, filter); // Pre-add match diff --git a/src/daemon/sledext.rs b/src/daemon/sledext.rs index 2180e84..927d0da 100644 --- a/src/daemon/sledext.rs +++ b/src/daemon/sledext.rs @@ -201,7 +201,7 @@ mod tests { #[test] fn tree_crud() { let filter = ok_filter(); - let db = TempDb::new(); + let db = TempDb::default(); let triggers = db.open_filter_triggers_tree(&filter).unwrap(); assert_eq!(BTreeMap::default(), triggers.as_map()); diff --git a/src/lib.rs b/src/lib.rs index dff7680..53b86dd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,6 +7,9 @@ )] #![allow(clippy::upper_case_acronyms, clippy::mutable_key_type)] +// Allow unwrap in tests +#![cfg_attr(test, allow(clippy::unwrap_used))] + pub mod cli; pub mod client; pub mod concepts; diff --git a/src/tests.rs b/src/tests.rs index 9b01996..4039910 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -1,4 +1,3 @@ -#![allow(clippy::unwrap_used)] #![cfg(test)] use std::{ @@ -61,8 +60,8 @@ pub struct TempDb { _tempdir: TempDir, } -impl TempDb { - pub fn new() -> Self { +impl Default for TempDb { + fn default() -> Self { let _tempdir = TempDir::new().unwrap(); let db = sled::open(_tempdir.path()).unwrap(); TempDb { _tempdir, db }