couchdb_orm/tests/utils/
mod.rs1use std::fs;
18use std::path::PathBuf;
19use std::str::FromStr;
20
21#[allow(dead_code)]
22pub const TESTS_FOLDER: &'static str = "__tests__";
23
24#[allow(dead_code)]
25pub fn root_test_path() -> PathBuf {
26 std::env::current_dir()
27 .unwrap()
28 .join(PathBuf::from_str(TESTS_FOLDER).unwrap())
29}
30
31#[allow(dead_code)]
32pub fn clean_meta_dir(rootdir: &PathBuf) {
33 let meta_path = rootdir.join(PathBuf::from("_meta"));
34 if meta_path.exists() {
35 fs::remove_dir_all(&meta_path).expect("failed to clean test _meta dir")
36 }
37}
38
39#[allow(dead_code)]
40pub fn clean_test_dir(rootdir: &PathBuf) {
41 if rootdir.exists() {
42 fs::remove_dir_all(&rootdir).expect("failed to clean test dir")
43 }
44}
45
46#[allow(dead_code)]
47pub fn create_tests_folder() {
48 fs::create_dir_all(TESTS_FOLDER).unwrap()
49}
50
51#[allow(dead_code)]
52pub fn create_test_dir(path: &str) -> PathBuf {
53 let p = root_test_path().join(path);
54 if p.exists() {
55 fs::remove_dir_all(&p).expect("failed destroy test dir")
56 }
57 fs::create_dir_all(&p).unwrap();
58 p
59}