summaryrefslogtreecommitdiff
path: root/crates/env/env_test/src/lib.rs
blob: 9ea3eccacfc5805852e599a8c1915bfbf9dbaf55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use std::{
    env::{current_dir, set_current_dir},
    path::PathBuf,
};

use tokio::fs;

#[cfg(test)]
pub mod test_vault_setup_and_member_register;

#[cfg(test)]
pub mod test_virtual_file_creation_and_update;

pub async fn get_test_dir(area: &str) -> Result<PathBuf, std::io::Error> {
    let dir = current_dir()?.join(".temp").join("test").join(area);
    if !dir.exists() {
        std::fs::create_dir_all(&dir)?;
    } else {
        // Regenerate existing directory
        fs::remove_dir_all(&dir).await?;
        fs::create_dir_all(&dir).await?;
    }
    Ok(dir)
}