Added delete error.
This commit is contained in:
parent
a22207f3b3
commit
085972060b
@ -199,12 +199,16 @@ impl MoreThanText {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn delete_entry(&self, id: &str) {
|
async fn delete_entry(&self, id: &str) -> Result<(), DBError> {
|
||||||
let mut cache = self.cache.lock().await;
|
let mut cache = self.cache.lock().await;
|
||||||
cache.remove(id);
|
cache.remove(id);
|
||||||
match remove_file(Path::new(&self.filename(id))).await {
|
match remove_file(Path::new(&self.filename(id))).await {
|
||||||
Ok(_) => (),
|
Ok(_) => Ok(()),
|
||||||
Err(_) => (),
|
Err(err) => {
|
||||||
|
let mut error = DBError::new("data delete");
|
||||||
|
error.add_source(err);
|
||||||
|
Err(error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -446,7 +450,7 @@ mod cache {
|
|||||||
.add_entry(CacheType::Raw("delete".to_string()))
|
.add_entry(CacheType::Raw("delete".to_string()))
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
mtt.db.delete_entry(&id).await;
|
mtt.db.delete_entry(&id).await.unwrap();
|
||||||
match mtt.db.get_entry(&id).await {
|
match mtt.db.get_entry(&id).await {
|
||||||
Ok(_) => assert!(false, "Entry should be removed from cache."),
|
Ok(_) => assert!(false, "Entry should be removed from cache."),
|
||||||
Err(_) => (),
|
Err(_) => (),
|
||||||
@ -456,7 +460,16 @@ mod cache {
|
|||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
async fn remove_missing_entry() {
|
async fn remove_missing_entry() {
|
||||||
let mtt = MTT::new().await;
|
let mtt = MTT::new().await;
|
||||||
mtt.db.delete_entry("missing").await;
|
let msg = "could not remove file";
|
||||||
|
match mtt.db.delete_entry("missing").await {
|
||||||
|
Ok(_) => assert!(false, "This should produce a write failure."),
|
||||||
|
Err(err) => {
|
||||||
|
assert_eq!(err.to_string(), "data delete");
|
||||||
|
assert!(err.source().is_some(), "Must include the source error.");
|
||||||
|
let err_msg = err.source().unwrap().to_string();
|
||||||
|
assert!(err_msg.contains(msg), "'{}' not in '{}'", msg, err_msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
|
Loading…
Reference in New Issue
Block a user