Test for different README.md in all directories.
@@ -4,7 +4,7 @@ use fixtures::{server, Error, TestServer, DIRECTORIES, FILES};
use rstest::rstest;
use select::predicate::Attr;
use select::{document::Document, node::Node};
-use std::fs::{create_dir_all, File};
+use std::fs::{remove_file, File};
use std::io::Write;
#[rstest]
@@ -26,38 +26,34 @@ fn no_readme_contents(server: TestServer) -> Result<(), Error> {
}
#[rstest(
- makedir,
- dir,
- content,
- case(false, "", "Test Hello Yes"),
- case(false, "/dira/", "This is dira/readme.md"),
- case(false, "/dirb/", "This is dirb/readme.md"),
- case(true, "/readme-dira/", "This is readme-dira/README.md")
+ readme_name,
+ case("Readme.md"),
+ case("readme.md"),
+ case("README.md"),
+ case("README.MD"),
+ case("ReAdMe.Md")
)]
/// Show readme contents when told to if there is readme.md/README.md file
fn show_readme_contents(
#[with(&["--readme"])] server: TestServer,
- makedir: bool,
- dir: &str,
- content: &str,
+ readme_name: &str,
) -> Result<(), Error> {
- if makedir {
- let tempdir = server.path().join(dir.strip_prefix("/").unwrap());
- create_dir_all(tempdir.clone()).unwrap();
- let mut readme_file = File::create(tempdir.join("README.md"))?;
+ for dir in DIRECTORIES {
+ let readme_path = server.path().join(dir).join(readme_name);
+ let mut readme_file = File::create(&readme_path)?;
readme_file
- .write(content.to_string().as_bytes())
- .expect("Couldn't write README.md");
- }
-
+ .write(
+ format!("Contents of {}", readme_name)
+ .to_string()
+ .as_bytes(),
+ )
+ .expect("Couldn't write readme");
let body = reqwest::blocking::get(server.url().join(dir)?)?.error_for_status()?;
let parsed = Document::from_read(body)?;
- if !makedir {
for &file in FILES {
assert!(parsed.find(|x: &Node| x.text() == file).next().is_some());
}
- }
assert!(parsed.find(Attr("id", "readme")).next().is_some());
assert!(parsed.find(Attr("id", "readme-filename")).next().is_some());
@@ -67,8 +63,7 @@ fn show_readme_contents(
.next()
.unwrap()
.text()
- .to_lowercase()
- == "readme.md"
+ == readme_name
);
assert!(parsed.find(Attr("id", "readme-contents")).next().is_some());
assert!(
@@ -78,8 +73,9 @@ fn show_readme_contents(
.unwrap()
.text()
.trim()
- == content
+ == format!("Contents of {}", readme_name)
);
-
+ remove_file(readme_path).unwrap();
+ }
Ok(())
}
