Added delete entry.
This commit is contained in:
parent
6229671212
commit
a22207f3b3
@ -1,7 +1,7 @@
|
||||
pub mod error;
|
||||
|
||||
use async_std::{
|
||||
fs::{create_dir, read, write},
|
||||
fs::{create_dir, read, remove_file, write},
|
||||
path::Path,
|
||||
sync::{Arc, Mutex},
|
||||
task::{sleep, spawn},
|
||||
@ -198,6 +198,15 @@ impl MoreThanText {
|
||||
cache.insert(id.to_string(), data);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn delete_entry(&self, id: &str) {
|
||||
let mut cache = self.cache.lock().await;
|
||||
cache.remove(id);
|
||||
match remove_file(Path::new(&self.filename(id))).await {
|
||||
Ok(_) => (),
|
||||
Err(_) => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@ -429,6 +438,27 @@ mod cache {
|
||||
}
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn remove_entry() {
|
||||
let mtt = MTT::new().await;
|
||||
let id = mtt
|
||||
.db
|
||||
.add_entry(CacheType::Raw("delete".to_string()))
|
||||
.await
|
||||
.unwrap();
|
||||
mtt.db.delete_entry(&id).await;
|
||||
match mtt.db.get_entry(&id).await {
|
||||
Ok(_) => assert!(false, "Entry should be removed from cache."),
|
||||
Err(_) => (),
|
||||
};
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn remove_missing_entry() {
|
||||
let mtt = MTT::new().await;
|
||||
mtt.db.delete_entry("missing").await;
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn remove_older() {
|
||||
let mtt = MTT::new().await;
|
||||
|
Loading…
Reference in New Issue
Block a user