From 7b598b549ca14d45ac0a8369ed5e564db0f0479f Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Fri, 6 Jan 2023 11:50:26 +0100 Subject: [PATCH] fix: unit tests --- src/config.rs | 12 +++++++----- src/ip.rs | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/config.rs b/src/config.rs index 6dcc08f..edabe5f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -138,9 +138,9 @@ impl Context { } pub async fn load(&mut self) -> Result<(), Box> { - #[cfg(test)] - return Ok(()); - + if cfg!(test) { + return Ok(()); + } self.discovery = self.discovery().await?; self.cfg.load(self.to_owned()).await?; self.create_sas().await?; @@ -185,8 +185,9 @@ impl Context { return Some(block.ipdata.clone()); } } else { - let starttime: DateTime = - DateTime::parse_from_rfc3339(ipdata.date.as_str()).unwrap(); + let starttime = DateTime::parse_from_rfc3339(ipdata.date.as_str()) + .unwrap() + .with_timezone(&chrono::Local); self.blocklist .entry(ipdata.ip.to_string()) .or_insert(BlockIpData { @@ -557,6 +558,7 @@ mod test { #[tokio::test] pub async fn test_blocklist_toblock() { let mut ctx = prepare_test_data().await; + ctx.gc_blocklist().await; let toblock = ctx.get_blocklist_toblock().await; assert_eq!(toblock.len(), 2); } diff --git a/src/ip.rs b/src/ip.rs index e8b1594..bc015fe 100644 --- a/src/ip.rs +++ b/src/ip.rs @@ -32,7 +32,7 @@ pub struct BlockIpData { pub ipdata: IpData, pub tryfail: i64, pub blocktime: i64, - pub starttime: DateTime, + pub starttime: DateTime, } impl PartialEq for IpData {