Merge pull request #760 from matthiasbeyer/libimagstore/store-tests-extend-create-delete-get-test

libimagstore/store-tests: extend create delete get test
This commit is contained in:
Matthias Beyer 2016-09-21 12:17:33 +02:00 committed by GitHub
commit 7124a1d27e
2 changed files with 31 additions and 11 deletions

View file

@ -62,7 +62,8 @@ mod fs {
};
}
pub fn remove_file(_: &PathBuf) -> Result<(), SE> {
pub fn remove_file(path: &PathBuf) -> Result<(), SE> {
MAP.lock().unwrap().remove(path);
Ok(())
}

View file

@ -459,11 +459,20 @@ impl Store {
///
/// This executes the {pre,post}_retrieve_aspects hooks.
pub fn get<'a, S: IntoStoreId + Clone>(&'a self, id: S) -> Result<Option<FileLockEntry<'a>>> {
let id_copy = try!(id.clone().into_storeid()).with_base(self.path().clone());
if !id_copy.exists() {
debug!("Does not exist: {:?}", id_copy);
let id = try!(id.into_storeid()).with_base(self.path().clone());
let exists = try!(self.entries
.read()
.map(|map| map.contains_key(&id))
.map_err(|_| SE::new(SEK::LockPoisoned, None))
.map_err_into(SEK::GetCallError)
);
if !exists && !id.exists() {
debug!("Does not exist in internal cache or filesystem: {:?}", id);
return Ok(None);
}
self.retrieve(id).map(Some).map_err_into(SEK::GetCallError)
}
@ -2196,28 +2205,38 @@ mod store_tests {
}
#[test]
fn test_store_create_delete_get() {
fn test_store_get_create_get_delete_get() {
let store = get_store();
for n in 1..100 {
let res = store.get(PathBuf::from(format!("test-{}", n)));
assert!(match res { Ok(None) => true, _ => false, })
}
for n in 1..100 {
let s = format!("test-{}", n);
let entry = store.create(PathBuf::from(s.clone())).unwrap();
assert!(entry.verify().is_ok());
let loc = entry.get_location().clone().into_pathbuf().unwrap();
assert!(loc.starts_with("/"));
assert!(loc.ends_with(s));
}
for n in 1..100 {
if n % 2 == 0 { continue; }
let s = format!("test-{}", n);
assert!(store.delete(PathBuf::from(s)).is_ok())
let res = store.get(PathBuf::from(format!("test-{}", n)));
assert!(match res { Ok(Some(_)) => true, _ => false, })
}
for n in 1..100 {
if n % 2 != 0 { continue; }
let s = format!("test-{}", n);
assert!(store.get(PathBuf::from(s)).is_ok())
assert!(store.delete(PathBuf::from(format!("test-{}", n))).is_ok())
}
for n in 1..100 {
let res = store.get(PathBuf::from(format!("test-{}", n)));
assert!(match res { Ok(None) => true, _ => false, })
}
}