Make web tests no longer mutate original files

This commit is contained in:
Lucien Greathouse
2018-06-24 19:37:30 -07:00
parent 5e08093609
commit be58598a3e
4 changed files with 55 additions and 13 deletions

View File

@@ -1,5 +1,11 @@
use std::fs::{create_dir, copy};
use std::path::Path;
use std::io;
use rouille::Request;
use walkdir::WalkDir;
use librojo::web::Server;
pub trait HttpTestUtil {
@@ -20,3 +26,29 @@ impl HttpTestUtil for Server {
body
}
}
pub fn copy_recursive(from: &Path, to: &Path) -> io::Result<()> {
for entry in WalkDir::new(from) {
let entry = entry?;
let path = entry.path();
let new_path = to.join(path.strip_prefix(from).unwrap());
let file_type = entry.file_type();
if file_type.is_dir() {
match create_dir(new_path) {
Ok(_) => {},
Err(err) => match err.kind() {
io::ErrorKind::AlreadyExists => {},
_ => panic!(err),
}
}
} else if file_type.is_file() {
copy(path, new_path)?;
} else {
unimplemented!("no symlinks please");
}
}
Ok(())
}