Refactored test database setup.
This commit is contained in:
parent
8f704844c3
commit
14c6c9dffe
@ -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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user