|
@@ -60,7 +60,8 @@ impl RocksDb {
|
|
Ok(Self { db })
|
|
Ok(Self { db })
|
|
}
|
|
}
|
|
|
|
|
|
- /// Creates a new instance, passing just the path, the default options are passed
|
|
|
|
|
|
+ /// Creates a new instance, passing just the path, the default options are
|
|
|
|
+ /// passed
|
|
pub fn new<T: AsRef<Path>>(path: T) -> Result<Self, Error> {
|
|
pub fn new<T: AsRef<Path>>(path: T) -> Result<Self, Error> {
|
|
let mut options = Options::default();
|
|
let mut options = Options::default();
|
|
options.create_if_missing(true);
|
|
options.create_if_missing(true);
|
|
@@ -273,88 +274,13 @@ impl Storage for RocksDb {
|
|
}
|
|
}
|
|
|
|
|
|
#[cfg(test)]
|
|
#[cfg(test)]
|
|
-mod test {
|
|
|
|
- use super::*;
|
|
|
|
- use crate::test;
|
|
|
|
- use rand::Rng;
|
|
|
|
-
|
|
|
|
- // Get current nanoseconds and use the last 3 digits as a random number (because
|
|
|
|
- // sometimes it comes as 0)
|
|
|
|
- pub fn unique_nanoseconds() -> u128 {
|
|
|
|
- let mut rng = rand::thread_rng();
|
|
|
|
- let random_number = rng.gen_range(0..999);
|
|
|
|
-
|
|
|
|
- let ts = std::time::SystemTime::now()
|
|
|
|
- .duration_since(std::time::UNIX_EPOCH)
|
|
|
|
- .expect("time")
|
|
|
|
- .as_nanos();
|
|
|
|
-
|
|
|
|
- ts.checked_add(random_number).unwrap_or(ts)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- #[test]
|
|
|
|
- fn store_and_get() {
|
|
|
|
- let db = RocksDb::new(format!("tests/db/{}", unique_nanoseconds())).expect("db");
|
|
|
|
- test::store_and_get(&db)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- #[test]
|
|
|
|
- fn records_are_sorted_by_date_desc() {
|
|
|
|
- let db = RocksDb::new(format!("tests/db/{}", unique_nanoseconds())).expect("db");
|
|
|
|
- test::records_are_sorted_by_date_desc(&db)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- #[test]
|
|
|
|
- fn filter_by_references_zero_match() {
|
|
|
|
- let db = RocksDb::new(format!("tests/db/{}", unique_nanoseconds())).expect("db");
|
|
|
|
- test::filter_by_references_zero_match(&db)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- #[test]
|
|
|
|
- fn filter_by_references_and_kind() {
|
|
|
|
- let db = RocksDb::new(format!("tests/db/{}", unique_nanoseconds())).expect("db");
|
|
|
|
- test::filter_by_references_and_kind(&db)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- #[test]
|
|
|
|
- fn get_event_and_related_events() {
|
|
|
|
- let db = RocksDb::new(format!("tests/db/{}", unique_nanoseconds())).expect("db");
|
|
|
|
- test::get_event_and_related_events(&db)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- #[test]
|
|
|
|
- fn filter_by_author() {
|
|
|
|
- let db = RocksDb::new(format!("tests/db/{}", unique_nanoseconds())).expect("db");
|
|
|
|
- test::filter_by_author(&db)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- #[test]
|
|
|
|
- fn filter_by_authors() {
|
|
|
|
- let db = RocksDb::new(format!("tests/db/{}", unique_nanoseconds())).expect("db");
|
|
|
|
- test::filter_by_authors(&db)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- #[test]
|
|
|
|
- fn filter_kind() {
|
|
|
|
- let db = RocksDb::new(format!("tests/db/{}", unique_nanoseconds())).expect("db");
|
|
|
|
- test::filter_kind(&db)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- #[test]
|
|
|
|
- fn filter_by_references() {
|
|
|
|
- let db = RocksDb::new(format!("tests/db/{}", unique_nanoseconds())).expect("db");
|
|
|
|
- test::filter_by_references(&db)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- #[test]
|
|
|
|
- fn filter_by_author_and_kinds() {
|
|
|
|
- let db = RocksDb::new(format!("tests/db/{}", unique_nanoseconds())).expect("db");
|
|
|
|
- test::filter_by_author_and_kinds(&db)
|
|
|
|
- }
|
|
|
|
|
|
+fn new_instance(path: &str) -> RocksDb {
|
|
|
|
+ RocksDb::new(&path).expect("valid db")
|
|
|
|
+}
|
|
|
|
|
|
- #[test]
|
|
|
|
- fn get_local_events() {
|
|
|
|
- let db = RocksDb::new(format!("tests/db/{}", unique_nanoseconds())).expect("db");
|
|
|
|
- test::get_local_events(&db)
|
|
|
|
- }
|
|
|
|
|
|
+#[cfg(test)]
|
|
|
|
+fn destroy_instance(path: &str) {
|
|
|
|
+ std::fs::remove_dir_all(path).expect("deleted file");
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+crate::storage_test!(RocksDb, new_instance, destroy_instance);
|