diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/fixtures/mod.rs | 17 | ||||
-rw-r--r-- | tests/serve_request.rs | 19 |
2 files changed, 31 insertions, 5 deletions
diff --git a/tests/fixtures/mod.rs b/tests/fixtures/mod.rs index 9cfd2cf..d55f022 100644 --- a/tests/fixtures/mod.rs +++ b/tests/fixtures/mod.rs @@ -4,13 +4,18 @@ use port_check::free_local_port; use rstest::fixture; /// Error type used by tests -pub type Error = Box<std::error::Error>; +pub type Error = Box<dyn std::error::Error>; /// File names for testing purpose #[allow(dead_code)] pub static FILES: &[&str] = &["test.txt", "test.html", "test.mkv"]; -/// Test fixture which creates a temporary directory with a few files inside. +/// Directory names for testing purpose +#[allow(dead_code)] +pub static DIRECTORIES: &[&str] = &["dira/", "dirb/", "dirc/"]; + +/// Test fixture which creates a temporary directory with a few files and directories inside. +/// The directories also contain files. #[fixture] #[allow(dead_code)] pub fn tmpdir() -> TempDir { @@ -21,6 +26,14 @@ pub fn tmpdir() -> TempDir { .write_str("Test Hello Yes") .expect("Couldn't write to file"); } + for &directory in DIRECTORIES { + for &file in FILES { + tmpdir + .child(format!("{}{}", directory, file)) + .write_str(&format!("This is {}{}", directory, file)) + .expect("Couldn't write to file"); + } + } tmpdir } diff --git a/tests/serve_request.rs b/tests/serve_request.rs index ef346b2..a3970d7 100644 --- a/tests/serve_request.rs +++ b/tests/serve_request.rs @@ -2,9 +2,10 @@ mod fixtures; use assert_cmd::prelude::*; use assert_fs::fixture::TempDir; -use fixtures::{port, tmpdir, Error, FILES}; +use fixtures::{port, tmpdir, Error, DIRECTORIES, FILES}; use rstest::rstest; use select::document::Document; +use select::node::Node; use select::predicate::Text; use std::process::{Command, Stdio}; use std::thread::sleep; @@ -22,7 +23,7 @@ fn serves_requests_with_no_options(tmpdir: TempDir) -> Result<(), Error> { let body = reqwest::get("http://localhost:8080")?.error_for_status()?; let parsed = Document::from_read(body)?; for &file in FILES { - assert!(parsed.find(Text).any(|x| x.text() == file)); + assert!(parsed.find(|x: &Node| x.text() == file).next().is_some()); } child.kill()?; @@ -44,7 +45,19 @@ fn serves_requests_with_non_default_port(tmpdir: TempDir, port: u16) -> Result<( let body = reqwest::get(format!("http://localhost:{}", port).as_str())?.error_for_status()?; let parsed = Document::from_read(body)?; for &file in FILES { - assert!(parsed.find(Text).any(|x| x.text() == file)); + assert!(parsed.find(|x: &Node| x.text() == file).next().is_some()); + } + for &directory in DIRECTORIES { + assert!(parsed + .find(|x: &Node| x.text() == directory) + .next() + .is_some()); + let dir_body = reqwest::get(format!("http://localhost:{}/{}", port, directory).as_str())? + .error_for_status()?; + let dir_body_parsed = Document::from_read(dir_body)?; + for &file in FILES { + assert!(dir_body_parsed.find(|x: &Node| x.text() == file).next().is_some()); + } } child.kill()?; |