stranger-site-gen/tests/render-structure.rs

50 lines
1.6 KiB
Rust
Raw Normal View History

2023-03-30 20:30:26 -04:00
use std::path::PathBuf;
use color_eyre::eyre::{ensure, Context, Result};
use stranger_site_gen::site::Site;
use walkdir::WalkDir;
/// Test that rendering a site produces the correct overall structure, does not test the contents of
/// the generated files
#[test]
fn render_structure() -> Result<()> {
// Get a pair of temporary directories
let tempdir_input = tempfile::tempdir().context("Failed to get temporary directory")?;
let tempdir_input_path = tempdir_input.path();
let tempdir_output = tempfile::tempdir().context("Failed to get temporary directory")?;
let tempdir_output_path = tempdir_output.path();
// Generate our site
let mut site = Site::default();
// Write it out
site.write(tempdir_input_path)
.context("Failed to write out site")?;
// Now render the site to the output path
site.render(tempdir_input_path, tempdir_output_path)
.context("Failed to render site")?;
// Generate out list of known good paths
let mut good_paths: Vec<_> = [
"index.html",
"posts/new-blog-who-this.html",
"statics/.gitkeep",
"styles/default.css",
"styles/index.css",
"styles/post.css",
]
.into_iter()
.map(PathBuf::from)
.collect();
good_paths.sort();
// Now walk the output directory
let mut output_paths = Vec::new();
for item in WalkDir::new(tempdir_output_path) {
let item = item.context("Failed walking output")?.into_path();
if item.is_file() {
output_paths.push(item);
}
}
output_paths.sort();
// Compare the results
assert_eq!(good_paths, output_paths);
Ok(())
}