From 96ed47456874ad7ad81fc1b347a27d151d7db76e Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Mon, 19 Dec 2022 08:12:32 -0500 Subject: [PATCH] update_entry updates file. --- src/morethantext/mod.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/morethantext/mod.rs b/src/morethantext/mod.rs index 8d93e17..1f21fe2 100644 --- a/src/morethantext/mod.rs +++ b/src/morethantext/mod.rs @@ -1,7 +1,7 @@ pub mod error; use async_std::{ - fs::{create_dir, read, write}, + fs::{create_dir, write}, path::Path, sync::{Arc, Mutex}, }; @@ -99,6 +99,9 @@ impl MoreThanText { Ok(_) => (), Err(err) => return Err(err), } + write(Path::new(&self.dir).join(&id), entry.to_bytes()) + .await + .unwrap(); let mut cache = self.cache.lock().await; cache.insert(id.to_string(), entry); Ok(()) @@ -177,6 +180,7 @@ mod init { #[cfg(test)] mod cache { use super::*; + use async_std::fs::read; use setup::MTT; use std::error::Error; @@ -238,12 +242,12 @@ mod cache { .await .unwrap(); let expected = "different"; - mtt.db - .update_entry(&id, CacheEntry::Raw(expected.to_string())) - .await - .unwrap(); + let expect = CacheEntry::Raw(expected.to_string()); + mtt.db.update_entry(&id, expect.clone()).await.unwrap(); let output = mtt.db.get_entry(&id).await.unwrap(); assert_eq!(output.to_string(), expected); + let content = read(mtt.dir.path().join(DATA).join(id)).await.unwrap(); + assert_eq!(content, expect.to_bytes()); } #[async_std::test]