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(())
}

View File

@@ -1,6 +1,8 @@
extern crate rouille;
extern crate serde_json;
extern crate serde;
extern crate tempfile;
extern crate walkdir;
extern crate librojo;
@@ -21,12 +23,17 @@ use librojo::{
#[test]
fn empty() {
let project_path = {
let original_project_path = {
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
path.push("test-projects/empty");
path
};
let project_tempdir = tempfile::tempdir().unwrap();
let project_path = project_tempdir.path();
copy_recursive(&original_project_path, &project_path).unwrap();
let project = Project::load(&project_path).unwrap();
let mut session = Session::new(project.clone());
session.start();
@@ -64,12 +71,17 @@ fn empty() {
#[test]
fn one_partition() {
let project_path = {
let original_project_path = {
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
path.push("test-projects/one-partition");
path
};
let project_tempdir = tempfile::tempdir().unwrap();
let project_path = project_tempdir.path();
copy_recursive(&original_project_path, &project_path).unwrap();
let project = Project::load(&project_path).unwrap();
let mut session = Session::new(project.clone());
session.start();
@@ -202,11 +214,7 @@ fn one_partition() {
};
{
let temp_name = {
let mut path = project_path.clone();
path.push("lib/c.client.lua");
path
};
let temp_name = project_path.join("lib/c.client.lua");
{
let mut file = File::create(&temp_name).unwrap();