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(()) Ok(())
} }

View file

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