update_entry updates file.

This commit is contained in:
Jeff Baskin 2022-12-19 08:12:32 -05:00
parent 3e203b40c0
commit 96ed474568

View File

@ -1,7 +1,7 @@
pub mod error; pub mod error;
use async_std::{ use async_std::{
fs::{create_dir, read, write}, fs::{create_dir, write},
path::Path, path::Path,
sync::{Arc, Mutex}, sync::{Arc, Mutex},
}; };
@ -99,6 +99,9 @@ impl MoreThanText {
Ok(_) => (), Ok(_) => (),
Err(err) => return Err(err), Err(err) => return Err(err),
} }
write(Path::new(&self.dir).join(&id), entry.to_bytes())
.await
.unwrap();
let mut cache = self.cache.lock().await; let mut cache = self.cache.lock().await;
cache.insert(id.to_string(), entry); cache.insert(id.to_string(), entry);
Ok(()) Ok(())
@ -177,6 +180,7 @@ mod init {
#[cfg(test)] #[cfg(test)]
mod cache { mod cache {
use super::*; use super::*;
use async_std::fs::read;
use setup::MTT; use setup::MTT;
use std::error::Error; use std::error::Error;
@ -238,12 +242,12 @@ mod cache {
.await .await
.unwrap(); .unwrap();
let expected = "different"; let expected = "different";
mtt.db let expect = CacheEntry::Raw(expected.to_string());
.update_entry(&id, CacheEntry::Raw(expected.to_string())) mtt.db.update_entry(&id, expect.clone()).await.unwrap();
.await
.unwrap();
let output = mtt.db.get_entry(&id).await.unwrap(); let output = mtt.db.get_entry(&id).await.unwrap();
assert_eq!(output.to_string(), expected); 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] #[async_std::test]