From 3e723f35bdf68df7c210b8130db7f9dd967a9767 Mon Sep 17 00:00:00 2001 From: Jerboa-app Date: Tue, 30 Apr 2024 06:45:19 +0100 Subject: [PATCH] Adds test to test last refresh time --- src/content/mod.rs | 5 +++++ src/content/pages/page.rs | 1 - tests/test_content.rs | 16 +++++++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/content/mod.rs b/src/content/mod.rs index a45c779..530df5b 100644 --- a/src/content/mod.rs +++ b/src/content/mod.rs @@ -123,6 +123,11 @@ impl Content self.uri.clone() } + pub fn get_last_refreshed(&self) -> SystemTime + { + self.last_refreshed.clone() + } + pub fn utf8_body(&self) -> Result { String::from_utf8(self.body.clone()) diff --git a/src/content/pages/page.rs b/src/content/pages/page.rs index dc894b0..27f5176 100644 --- a/src/content/pages/page.rs +++ b/src/content/pages/page.rs @@ -113,7 +113,6 @@ impl IntoResponse for Page { pub fn is_page(uri: &str, domain: &str) -> bool { - let domain_escaped = domain.replace("https://", "").replace("http://", "").replace(".", r"\."); match Regex::new(format!(r"((^|(http)(s|)://){})(/|/[^\.]+|/[^\.]+.html|$)$",domain_escaped).as_str()) { diff --git a/tests/test_content.rs b/tests/test_content.rs index 8cbe9cb..84cebe0 100644 --- a/tests/test_content.rs +++ b/tests/test_content.rs @@ -3,9 +3,10 @@ mod common; #[cfg(test)] mod test_content { - use std::{fs::remove_file, path::Path}; + use std::{fs::remove_file, path::Path, thread::sleep, time}; use busser::{content::Content, filesystem::file::{file_hash, write_file_bytes, Observed}, util::read_bytes}; + use chrono::Duration; #[test] fn test_load_content() @@ -55,5 +56,18 @@ mod test_content let _ = remove_file(path); } + #[test] + fn test_last_refreshed() + { + let mut content = Content::new("tests/pages/a.html", "tests/pages/a.html", 3600); + assert!(content.load_from_file().is_ok()); + let a = content.get_last_refreshed(); + sleep(time::Duration::from_secs(2)); + assert!(content.load_from_file().is_ok()); + let b = content.get_last_refreshed(); + assert!(a < b); + } + + }