Skip to content

Commit

Permalink
Adds test to test last refresh time
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerboa-app committed Apr 30, 2024
1 parent 46d5e0f commit 3e723f3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/content/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, std::string::FromUtf8Error>
{
String::from_utf8(self.body.clone())
Expand Down
1 change: 0 additions & 1 deletion src/content/pages/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down
16 changes: 15 additions & 1 deletion tests/test_content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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);
}


}

0 comments on commit 3e723f3

Please sign in to comment.