add tests for history::find
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful

This commit is contained in:
Paul Campbell 2023-07-28 07:50:55 +01:00
parent 20a4ef59d9
commit 1219eef089
4 changed files with 91 additions and 0 deletions

View file

@ -15,3 +15,86 @@ pub fn find(link: &Link, file_name: &str) -> Result<bool> {
} }
Ok(false) // is not already downloaded Ok(false) // is not already downloaded
} }
#[cfg(test)]
mod test {
use crate::{history::Link, test_utils::create_text_file};
use super::*;
#[test]
fn true_if_line_exists() -> Result<()> {
//given
let (dir, file_name) =
create_text_file("file", include_bytes!("../../test/data/with-llamma.txt"))?;
let link = Link {
href: "llamma".to_string(),
rel: "".to_string(),
hreflang: None,
mime_type: None,
title: None,
length: None,
};
//when
let result = find(&link, &file_name)?;
//then
drop(dir);
assert_eq!(result, true);
Ok(())
}
#[test]
fn false_if_line_absent() -> Result<()> {
//given
let (dir, file_name) =
create_text_file("file", include_bytes!("../../test/data/without-llamma.txt"))?;
let link = Link {
href: "llamma".to_string(),
rel: "".to_string(),
hreflang: None,
mime_type: None,
title: None,
length: None,
};
//when
let result = find(&link, &file_name)?;
//then
drop(dir);
assert_eq!(result, false);
Ok(())
}
#[test]
fn false_if_embedded_within_line() -> Result<()> {
//given
let (dir, file_name) = create_text_file(
"file",
include_bytes!("../../test/data/with-embedded-llamma.txt"),
)?;
let link = Link {
href: "llamma".to_string(),
rel: "".to_string(),
hreflang: None,
mime_type: None,
title: None,
length: None,
};
//when
let result = find(&link, &file_name)?;
//then
drop(dir);
assert_eq!(result, false);
Ok(())
}
}

View file

@ -0,0 +1,3 @@
this is a text file
embedded llamma
it has three lines

View file

@ -0,0 +1,3 @@
this is a text file
llamma
it has three lines

View file

@ -0,0 +1,2 @@
this is a text file
it has three lines