1pub mod config;
2pub mod db;
3pub mod envs;
4pub mod node_type;
56use std::path::PathBuf;
7use std::{env, fs};
89use envs::FM_TEST_DIR_ENV;
10use tempfile::TempDir;
1112/// If `FM_TEST_DIR` is set, use it as a base, otherwise use a tempdir
13///
14/// Callers must hold onto the tempdir until it is no longer needed
15pub fn test_dir(pathname: &str) -> (PathBuf, Option<TempDir>) {
16let (parent, maybe_tmp_dir_guard) = if let Ok(directory) = env::var(FM_TEST_DIR_ENV) {
17 (directory, None)
18 } else {
19let random = format!("test-{}", rand::random::<u64>());
20let guard = tempfile::Builder::new().prefix(&random).tempdir().unwrap();
21let directory = guard.path().to_str().unwrap().to_owned();
22 (directory, Some(guard))
23 };
24let fullpath = PathBuf::from(parent).join(pathname);
25 fs::create_dir_all(fullpath.clone()).expect("Can make dirs");
26 (fullpath, maybe_tmp_dir_guard)
27}