wip: Render structure test

This commit is contained in:
Nathan McCarty 2023-03-30 20:30:26 -04:00
parent 962fb39dd2
commit 5078dee038
No known key found for this signature in database
2 changed files with 50 additions and 1 deletions

View File

@ -302,7 +302,7 @@ impl Site {
let output_dir = output_dir.as_ref();
let span = info_span!("Site::render", ?site_dir, ?output_dir);
let _enter = span.enter();
todo!()
todo!("Site::render stub")
}
}
/// Error encountered interacting with a [`Site`]

49
tests/render-structure.rs Normal file
View File

@ -0,0 +1,49 @@
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(())
}