summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-10-26 09:48:50 +0200
committerMatthias Beyer <mail@beyermatthias.de>2019-10-26 09:57:05 +0200
commit583f9727880e81b1827cfb33dbbd924589eda33c (patch)
tree9228d454df411dea7f5e23f167763410524a9098 /lib
parentd1078590c79e8ff2b836c08acfa9226118cc7975 (diff)
Add test: Test moving entry with writing to it before and after moving
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/core/libimagstore/src/store.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/core/libimagstore/src/store.rs b/lib/core/libimagstore/src/store.rs
index 5e029e48..1e195fb0 100644
--- a/lib/core/libimagstore/src/store.rs
+++ b/lib/core/libimagstore/src/store.rs
@@ -1226,4 +1226,43 @@ mod store_tests {
}
}
+ #[test]
+ fn test_moving_entry_with_writing_before_and_after() {
+ use crate::storeid::StoreId;
+ setup_logging();
+
+ let store = get_store();
+
+ let old_name = StoreId::new(PathBuf::from("old")).unwrap();
+ let new_name = StoreId::new(PathBuf::from("new")).unwrap();
+
+ debug!("Creating old entry");
+ {
+ let mut entry = store.create(old_name.clone()).unwrap();
+ entry.get_content_mut().push_str("first line");
+ drop(entry);
+ } // make sure entry is dropped
+
+ debug!("Moving");
+ store.move_by_id(old_name.clone(), new_name.clone()).unwrap();
+
+ debug!("Getting old entry again (should not work)");
+ assert!(store.get(old_name).unwrap().is_none());
+
+ debug!("Getting new entry");
+ {
+ let mut entry = store.get(new_name.clone()).unwrap().unwrap();
+ assert_eq!(entry.get_content(), "first line");
+ entry.get_content_mut().push_str("second line");
+ drop(entry);
+ } // make sure entry is dropped
+
+ {
+ debug!("Getting new entry again");
+ debug!("Store = {:#?}", store);
+ let new_entry = store.get(new_name).unwrap().unwrap();
+ assert_eq!(new_entry.get_content(), "first linesecond line");
+ }
+ }
+
}