couchdb_orm/tests/utils/
mod.rs

1// Copyright (C) 2020-2023  OpenToolAdd
2//
3// This program is free software: you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation, either version 3 of the License, or
6// (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11// GNU General Public License for more details.
12//
13// You should have received a copy of the GNU General Public License
14// along with this program.  If not, see <http://www.gnu.org/licenses/>.
15// contact: contact@tool-add.com
16
17use 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}