use tempfile::TempDir; use crate::config::AppConfig; use crate::db::Db; use crate::error::CreddyError; pub const TEST_PASSPHRASE: &'static str = "correct horse battery staple"; pub struct TestEnv { // we have to keep this around or the tempdir will be deleted as soon as it's dropped _dir: TempDir, pub config: AppConfig, } impl TestEnv { pub fn new() -> Result { let dir = tempfile::tempdir()?; let config = AppConfig::load_from(dir.path().to_path_buf())?; Ok(TestEnv { _dir: dir, config }) } pub fn db(&self) -> Result { Db::connect(&self.config, TEST_PASSPHRASE) } }