Add test for README.md file for `--readme`
@@ -4,6 +4,8 @@ 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::io::Write;
#[rstest]
/// Do not show readme contents by default
@@ -24,24 +26,38 @@ fn no_readme_contents(server: TestServer) -> Result<(), Error> {
}
#[rstest(
+ makedir,
dir,
content,
- case("", "Test Hello Yes"),
- case("/dira/", "This is dira/readme.md"),
- case("/dirb/", "This is dirb/readme.md")
+ 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")
)]
-/// Show readme contents when told to if there is readme.md file
+/// 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,
) -> 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"))?;
+ readme_file
+ .write(content.to_string().as_bytes())
+ .expect("Couldn't write README.md");
+ }
+
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());
@@ -51,6 +67,7 @@ fn show_readme_contents(
.next()
.unwrap()
.text()
+ .to_lowercase()
== "readme.md"
);
assert!(parsed.find(Attr("id", "readme-contents")).next().is_some());
