Files
creddy/src/test_data.rs
T
2026-11-18 10:14:36 -05:00

26 lines
674 B
Rust

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<TestEnv, CreddyError> {
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, CreddyError> {
Db::connect(&self.config, TEST_PASSPHRASE)
}
}