Added integration tests to make sure files are redirected as intended

This commit is contained in:
Michael-F-Bryan 2020-05-27 02:35:15 +08:00
parent b2d50392ea
commit 4c2318922f
No known key found for this signature in database
GPG Key ID: E9C602B0D9A998DC
1 changed files with 28 additions and 1 deletions

View File

@ -12,10 +12,11 @@ use mdbook::utils::fs::write_file;
use mdbook::MDBook; use mdbook::MDBook;
use select::document::Document; use select::document::Document;
use select::predicate::{Class, Name, Predicate}; use select::predicate::{Class, Name, Predicate};
use std::collections::HashMap;
use std::ffi::OsStr; use std::ffi::OsStr;
use std::fs; use std::fs;
use std::io::Write; use std::io::Write;
use std::path::Path; use std::path::{Path, PathBuf};
use tempfile::Builder as TempFileBuilder; use tempfile::Builder as TempFileBuilder;
use walkdir::{DirEntry, WalkDir}; use walkdir::{DirEntry, WalkDir};
@ -511,6 +512,32 @@ fn markdown_options() {
); );
} }
#[test]
fn redirects_are_emitted_correctly() {
let temp = DummyBook::new().build().unwrap();
let mut md = MDBook::load(temp.path()).unwrap();
// override the "outputs.html.redirect" table
let redirects: HashMap<PathBuf, String> = vec![
(PathBuf::from("index.html"), String::from("overview.html")),
(
PathBuf::from("nexted/page.md"),
String::from("https://rust-lang.org/"),
),
]
.into_iter()
.collect();
md.config.set("output.html.redirect", &redirects).unwrap();
md.build().unwrap();
for (original, redirect) in &redirects {
let redirect_file = md.build_dir_for("html").join(original);
let contents = fs::read_to_string(&redirect_file).unwrap();
assert!(contents.contains(redirect));
}
}
#[cfg(feature = "search")] #[cfg(feature = "search")]
mod search { mod search {
use crate::dummy_book::DummyBook; use crate::dummy_book::DummyBook;