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;
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]