wip: Render structure test
This commit is contained in:
parent
962fb39dd2
commit
5078dee038
|
@ -302,7 +302,7 @@ impl Site {
|
||||||
let output_dir = output_dir.as_ref();
|
let output_dir = output_dir.as_ref();
|
||||||
let span = info_span!("Site::render", ?site_dir, ?output_dir);
|
let span = info_span!("Site::render", ?site_dir, ?output_dir);
|
||||||
let _enter = span.enter();
|
let _enter = span.enter();
|
||||||
todo!()
|
todo!("Site::render stub")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Error encountered interacting with a [`Site`]
|
/// Error encountered interacting with a [`Site`]
|
||||||
|
|
|
@ -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(())
|
||||||
|
}
|
Loading…
Reference in New Issue