fix: unit tests

This commit is contained in:
Paul 2023-01-06 11:50:26 +01:00
parent 0ea292b28c
commit 7b598b549c
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>> {
#[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<FixedOffset> =
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);
}

View File

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