Added initialization failure.
This commit is contained in:
parent
8fada737ac
commit
c477a92945
@ -184,15 +184,21 @@ impl Entry {
|
|||||||
struct Cache;
|
struct Cache;
|
||||||
|
|
||||||
impl Cache {
|
impl Cache {
|
||||||
async fn new<P>(dir: P) -> Self
|
async fn new<P>(dir: P) -> Result<Self, DBError>
|
||||||
where
|
where
|
||||||
P: Into<PathBuf>,
|
P: Into<PathBuf>,
|
||||||
{
|
{
|
||||||
let pathbuf = dir.into();
|
let pathbuf = dir.into();
|
||||||
let entry = pathbuf.as_path().join(ENTRY);
|
let entry = pathbuf.as_path().join(ENTRY);
|
||||||
let store = DataType::new("store").unwrap();
|
let store = DataType::new("store").unwrap();
|
||||||
Entry::new(entry, store).await.unwrap();
|
match Entry::new(entry, store).await {
|
||||||
Self {}
|
Ok(_) => Ok(Self {}),
|
||||||
|
Err(err) => {
|
||||||
|
let mut error = DBError::new("initialization failure");
|
||||||
|
error.add_source(err);
|
||||||
|
Err(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -580,12 +586,13 @@ mod entry {
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod cache {
|
mod cache {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use std::error::Error;
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
|
|
||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
async fn create() {
|
async fn create() {
|
||||||
let dir = tempdir().unwrap();
|
let dir = tempdir().unwrap();
|
||||||
Cache::new(dir.path().to_str().unwrap()).await;
|
Cache::new(dir.path().to_str().unwrap()).await.unwrap();
|
||||||
let epoint = dir.path().join(ENTRY);
|
let epoint = dir.path().join(ENTRY);
|
||||||
assert!(
|
assert!(
|
||||||
epoint.is_file(),
|
epoint.is_file(),
|
||||||
@ -598,4 +605,25 @@ mod cache {
|
|||||||
Vec::<String>::new()
|
Vec::<String>::new()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[async_std::test]
|
||||||
|
async fn entry_failure() {
|
||||||
|
let dir = tempdir().unwrap();
|
||||||
|
let path = dir.path().join("bad").join("path");
|
||||||
|
match Cache::new(path).await {
|
||||||
|
Ok(_) => assert!(false, "Should have produced an error."),
|
||||||
|
Err(err) => {
|
||||||
|
assert_eq!(err.to_string(), "initialization failure");
|
||||||
|
assert!(err.source().is_some(), "Error should have a source.");
|
||||||
|
assert!(
|
||||||
|
err.source()
|
||||||
|
.unwrap()
|
||||||
|
.to_string()
|
||||||
|
.contains("failed to write"),
|
||||||
|
"Source Error Message: {}",
|
||||||
|
err.source().unwrap().to_string()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user