Refactored test database setup.
This commit is contained in:
		@@ -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)]
 | 
			
		||||
mod init {
 | 
			
		||||
    use super::*;
 | 
			
		||||
@@ -76,15 +97,12 @@ mod init {
 | 
			
		||||
#[cfg(test)]
 | 
			
		||||
mod cache {
 | 
			
		||||
    use super::*;
 | 
			
		||||
    use tempfile::tempdir;
 | 
			
		||||
    use setup::MTT;
 | 
			
		||||
 | 
			
		||||
    #[async_std::test]
 | 
			
		||||
    async fn  add_entry() {
 | 
			
		||||
        let dir = tempdir().unwrap();
 | 
			
		||||
        let db = MoreThanText::new(dir.path().to_str().unwrap()).await.unwrap();
 | 
			
		||||
    async fn add_entry() {
 | 
			
		||||
        let mtt = MTT::new().await;
 | 
			
		||||
        let data = CacheEntry::Raw("something".to_string());
 | 
			
		||||
        db.add_entry(data).await;
 | 
			
		||||
        drop(db);
 | 
			
		||||
        dir.close().unwrap();
 | 
			
		||||
        mtt.db.add_entry(data).await;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user