X-Git-Url: https://git.r.bdr.sh/rbdr/blog/blobdiff_plain/6352ebb0eb4cb83240c6d4998e0ef1375b041191..9c537e473ac117eadad86b68d21f3aaf8d8937c4:/src/archiver/raw.rs?ds=sidebyside diff --git a/src/archiver/raw.rs b/src/archiver/raw.rs index 5099f2b..5cac709 100644 --- a/src/archiver/raw.rs +++ b/src/archiver/raw.rs @@ -1,11 +1,49 @@ -use std::io::Result; -use std::path::PathBuf; -use crate::template::TemplateContext; +use crate::template::Context; use crate::utils::recursively_copy; +use std::io::Result; +use std::path::Path; -pub fn archive(archive_directory: &PathBuf, _: &PathBuf, target: &PathBuf, _: &TemplateContext) -> Result<()> { +pub fn archive(archive_directory: &Path, _: &Path, target: &Path, _: &Context) -> Result<()> { if archive_directory.exists() { return recursively_copy(archive_directory, target); } Ok(()) } + +#[cfg(test)] +mod tests { + use std::collections::HashMap; + use std::fs::create_dir_all; + + use super::*; + + use test_utilities::*; + + #[test] + fn test_copies_files() { + let test_dir = setup_test_dir(); + let archive_dir = test_dir.join("archive"); + let output_dir = test_dir.join("output"); + create_dir_all(&archive_dir).expect("Could not create archive test directory"); + create_dir_all(&output_dir).expect("Could not create output test directory"); + + create_test_file(&archive_dir.join("🤠"), "beep boop boop beep"); + + let context: Context = HashMap::new(); + + archive(&archive_dir, &test_dir, &output_dir, &context).expect("Archive failed"); + + assert_file_contents(&output_dir.join("🤠"), "beep boop boop beep"); + } + + #[test] + fn test_ignores_if_no_archive() { + let test_dir = setup_test_dir(); + let archive_dir = test_dir.join("archive"); + let output_dir = test_dir.join("output"); + + let context: Context = HashMap::new(); + + archive(&archive_dir, &test_dir, &output_dir, &context).expect("Archive failed"); + } +}