Refactored test database setup.

This commit is contained in:
Jeff Baskin 2022-12-03 10:22:54 -05:00
parent 8f704844c3
commit 14c6c9dffe
1 changed files with 25 additions and 7 deletions

View File

@ -33,6 +33,27 @@ impl MoreThanText {
} }
} }
#[cfg(test)]
mod setup {
use super::*;
use tempfile::{tempdir, TempDir};
pub struct MTT {
pub db: MoreThanText,
pub dir: TempDir,
}
impl MTT {
pub async fn new() -> Self {
let dir = tempdir().unwrap();
let db = MoreThanText::new(dir.path().to_str().unwrap())
.await
.unwrap();
Self { db: db, dir: dir }
}
}
}
#[cfg(test)] #[cfg(test)]
mod init { mod init {
use super::*; use super::*;
@ -76,15 +97,12 @@ mod init {
#[cfg(test)] #[cfg(test)]
mod cache { mod cache {
use super::*; use super::*;
use tempfile::tempdir; use setup::MTT;
#[async_std::test] #[async_std::test]
async fn add_entry() { async fn add_entry() {
let dir = tempdir().unwrap(); let mtt = MTT::new().await;
let db = MoreThanText::new(dir.path().to_str().unwrap()).await.unwrap();
let data = CacheEntry::Raw("something".to_string()); let data = CacheEntry::Raw("something".to_string());
db.add_entry(data).await; mtt.db.add_entry(data).await;
drop(db);
dir.close().unwrap();
} }
} }