fix: unit tests

This commit is contained in:
Paul 2023-01-06 11:50:26 +01:00
parent 443685018f
commit 53333b5e82
2 changed files with 8 additions and 6 deletions

View File

@ -138,9 +138,9 @@ impl Context {
} }
pub async fn load(&mut self) -> Result<(), Box<dyn std::error::Error>> { pub async fn load(&mut self) -> Result<(), Box<dyn std::error::Error>> {
#[cfg(test)] if cfg!(test) {
return Ok(()); return Ok(());
}
self.discovery = self.discovery().await?; self.discovery = self.discovery().await?;
self.cfg.load(self.to_owned()).await?; self.cfg.load(self.to_owned()).await?;
self.create_sas().await?; self.create_sas().await?;
@ -185,8 +185,9 @@ impl Context {
return Some(block.ipdata.clone()); return Some(block.ipdata.clone());
} }
} else { } else {
let starttime: DateTime<FixedOffset> = let starttime = DateTime::parse_from_rfc3339(ipdata.date.as_str())
DateTime::parse_from_rfc3339(ipdata.date.as_str()).unwrap(); .unwrap()
.with_timezone(&chrono::Local);
self.blocklist self.blocklist
.entry(ipdata.ip.to_string()) .entry(ipdata.ip.to_string())
.or_insert(BlockIpData { .or_insert(BlockIpData {
@ -557,6 +558,7 @@ mod test {
#[tokio::test] #[tokio::test]
pub async fn test_blocklist_toblock() { pub async fn test_blocklist_toblock() {
let mut ctx = prepare_test_data().await; let mut ctx = prepare_test_data().await;
ctx.gc_blocklist().await;
let toblock = ctx.get_blocklist_toblock().await; let toblock = ctx.get_blocklist_toblock().await;
assert_eq!(toblock.len(), 2); assert_eq!(toblock.len(), 2);
} }

View File

@ -32,7 +32,7 @@ pub struct BlockIpData {
pub ipdata: IpData, pub ipdata: IpData,
pub tryfail: i64, pub tryfail: i64,
pub blocktime: i64, pub blocktime: i64,
pub starttime: DateTime<FixedOffset>, pub starttime: DateTime<Local>,
} }
impl PartialEq for IpData { impl PartialEq for IpData {