Skip to content

Commit

Permalink
test(wip): add test for recursion and includes/excludes
Browse files Browse the repository at this point in the history
**THIS TEST IS NOT WORKING YET**
  • Loading branch information
JakeStanger committed Jan 9, 2022
1 parent a193500 commit 59b0649
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tests/snapshots_test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use std::collections::HashMap;
use std::{thread, time};
use dura::config::{Config, WatchConfig};
use dura::snapshots;
use crate::util::GitRepo;

mod util;

Expand Down Expand Up @@ -63,3 +67,58 @@ fn during_merge_conflicts() {
assert_eq!(status.dura_branch, format!("dura-{}", status.base_hash));
}

#[test]
fn change_single_file_in_multiple_repos() {
let parent_dir = tempfile::tempdir().unwrap();
let child_dir = tempfile::tempdir_in(parent_dir.path()).unwrap();

let mut repos = (0..3)
.map(|_| GitRepo::new_in(&parent_dir))
.collect::<Vec<_>>();

let mut child_repos = (0..3)
.map(|_| GitRepo::new_in(&child_dir))
.collect::<Vec<_>>();

let mut repo_map = HashMap::new();
repo_map.insert(
parent_dir.path().as_os_str().to_str().unwrap().to_string(),
WatchConfig {
exclude: vec![
repos[0].dir.path().to_str().unwrap().to_string(),
child_dir.path().as_os_str().to_str().unwrap().to_string(),
],
include: vec![child_repos[0].dir.path().to_str().unwrap().to_string()],
max_depth: 255
},
);

let config = Config {
pid: None,
repos: repo_map,
};

let mut dura = util::Dura::new();

config.save_to_path(&dura.config_path());

assert_ne!(None, dura.get_config());

repos.append(&mut child_repos);
for mut repo in repos {
repo.write_file("foo.txt");
repo.commit_all();

repo.change_file("foo.txt");

// FIXME: cannot find repo
let status = snapshots::capture(repo.dir.path()).unwrap().unwrap();

println!("{:?}", status);
}

assert_ne!(None, dura.pid(true));
let cfg = dura.get_config();
assert_ne!(None, cfg);
assert_eq!(dura.pid(true), cfg.unwrap().pid);
}
6 changes: 6 additions & 0 deletions tests/util.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{fs, path, ops, thread, time, env};
use std::path::Path;
use std::process::{Command, Child};

use tempfile;
Expand All @@ -20,6 +21,11 @@ impl GitRepo {
Self { dir, counter: 0 }
}

pub fn new_in<P: AsRef<Path>>(dir: P) -> Self {
let dir = tempfile::tempdir_in(dir).unwrap();
Self { dir, counter: 0 }
}

pub fn git(&self, args: &[&str]) -> Option<String> {
println!("$ git {}", args.join(" "));
let git_dir = self.dir.path().join(path::Path::new(".git"));
Expand Down

0 comments on commit 59b0649

Please sign in to comment.