diff --git a/src/morethantext/mod.rs b/src/morethantext/mod.rs index b7a4a2e..3f10b96 100644 --- a/src/morethantext/mod.rs +++ b/src/morethantext/mod.rs @@ -199,12 +199,16 @@ impl MoreThanText { Ok(()) } - async fn delete_entry(&self, id: &str) { + async fn delete_entry(&self, id: &str) -> Result<(), DBError> { let mut cache = self.cache.lock().await; cache.remove(id); match remove_file(Path::new(&self.filename(id))).await { - Ok(_) => (), - Err(_) => (), + Ok(_) => Ok(()), + 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())) .await .unwrap(); - mtt.db.delete_entry(&id).await; + mtt.db.delete_entry(&id).await.unwrap(); match mtt.db.get_entry(&id).await { Ok(_) => assert!(false, "Entry should be removed from cache."), Err(_) => (), @@ -456,7 +460,16 @@ mod cache { #[async_std::test] async fn remove_missing_entry() { 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]