Added error for missing cache entry.
This commit is contained in:
parent
bdcee41dcf
commit
d73a18be2d
@ -54,9 +54,12 @@ impl MoreThanText {
|
||||
return id;
|
||||
}
|
||||
|
||||
async fn get_entry(&self, id: &str) -> CacheEntry {
|
||||
async fn get_entry(&self, id: &str) -> Result<CacheEntry, DBError> {
|
||||
let cache = self.cache.lock().await;
|
||||
cache.get(id).unwrap().clone()
|
||||
match cache.get(id) {
|
||||
Some(id) => Ok(id.clone()),
|
||||
None => Err(DBError::new("cache entry not found")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -142,7 +145,16 @@ mod cache {
|
||||
let data = "something";
|
||||
let expected = CacheEntry::Raw(data.to_string());
|
||||
let id = mtt.db.add_entry(expected).await;
|
||||
let output = mtt.db.get_entry(&id).await;
|
||||
let output = mtt.db.get_entry(&id).await.unwrap();
|
||||
assert_eq!(output.to_string(), data);
|
||||
}
|
||||
|
||||
#[async_std::test]
|
||||
async fn retrieve_bad_id() {
|
||||
let mtt = MTT::new().await;
|
||||
match mtt.db.get_entry(&"Not Valid").await {
|
||||
Ok(_) => assert!(false, "Should have raised an error."),
|
||||
Err(err) => assert_eq!(err.to_string(), "cache entry not found"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user