test loading AppSession

This commit is contained in:
jfmonty2 committed 2026-11-18 10:14:36 -05:00
1 parent 0798124811
commit 5999aba0a5
2 files changed
+44 -14

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
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)
}
}