summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-09-01 10:44:53 +0200
committerMatthias Beyer <mail@beyermatthias.de>2019-09-01 13:36:39 +0200
commit87f2a0cb759dc508f3f58eb14519669c8e62ac67 (patch)
tree8ba8cd35cc63fb0531a41fcebefb07a68f0885f4
parent84135b1961bc2406a2c5f76cf3bf7da9d44be000 (diff)
Add Tests for Entries::{find_by_id_substr, find_by_id_startswith}
-rw-r--r--lib/core/libimagstore/src/iter.rs57
1 files changed, 57 insertions, 0 deletions
diff --git a/lib/core/libimagstore/src/iter.rs b/lib/core/libimagstore/src/iter.rs
index 3dfd2b2..78513f9 100644
--- a/lib/core/libimagstore/src/iter.rs
+++ b/lib/core/libimagstore/src/iter.rs
@@ -342,5 +342,62 @@ mod tests {
assert!(succeeded, "not all entries in iterator are from coll_3 collection");
}
+
+ #[test]
+ fn test_entries_iterator_substr() {
+ setup_logging();
+ let store = get_store();
+
+ let ids = {
+ let base = String::from("entry");
+ let variants = vec!["coll_1", "coll2", "coll_3"];
+ let modifier = |base: &String, v: &&str| {
+ StoreId::new(PathBuf::from(format!("{}/{}", *v, base))).unwrap()
+ };
+
+ generate_variants(&base, variants.iter(), &modifier)
+ };
+
+ for id in ids {
+ let _ = store.retrieve(id).unwrap();
+ }
+
+ let succeeded = store.entries()
+ .unwrap()
+ .find_by_id_substr("_")
+ .map(|id| { debug!("Processing id = {:?}", id); id })
+ .all(|id| id.unwrap().local_display_string().contains('_'));
+
+ assert!(succeeded, "not all entries in iterator contain '_'");
+ }
+
+ #[test]
+ fn test_entries_iterator_startswith() {
+ setup_logging();
+ let store = get_store();
+
+ let ids = {
+ let base = String::from("entry");
+ let variants = vec!["coll_1", "coll2", "coll_3"];
+ let modifier = |base: &String, v: &&str| {
+ StoreId::new(PathBuf::from(format!("{}/{}", *v, base))).unwrap()
+ };
+
+ generate_variants(&base, variants.iter(), &modifier)
+ };
+
+ for id in ids {
+ let _ = store.retrieve(id).unwrap();
+ }
+
+ let succeeded = store.entries()
+ .unwrap()
+ .find_by_id_startswith("entr")
+ .map(|id| { debug!("Processing id = {:?}", id); id })
+ .all(|id| id.unwrap().local_display_string().starts_with("entry"));
+
+ assert!(succeeded, "not all entries in iterator start with 'entr'");
+ }
+
}