From bf927fcabda412f5e9e839649f90e0743f142b6b Mon Sep 17 00:00:00 2001 From: Aiden McClelland Date: Fri, 24 Feb 2023 15:41:43 -0700 Subject: [PATCH] fix tests Co-authored-by: J H --- json-patch | 2 +- json-ptr | 2 +- patch-db-macro-internals/src/lib.rs | 12 +++++----- patch-db/src/store.rs | 6 ++--- patch-db/src/test.rs | 34 ++++------------------------- 5 files changed, 15 insertions(+), 41 deletions(-) diff --git a/json-patch b/json-patch index b92c0a0..1a18bb2 160000 --- a/json-patch +++ b/json-patch @@ -1 +1 @@ -Subproject commit b92c0a0d536d42a31f59b8f079e382c301eca38a +Subproject commit 1a18bb258fb159a66461c616e7ad16c14eb8fce3 diff --git a/json-ptr b/json-ptr index 2415675..9634051 160000 --- a/json-ptr +++ b/json-ptr @@ -1 +1 @@ -Subproject commit 2415675acd1bb60cea3f69e590a7923bbc6398e8 +Subproject commit 963405175ac72b94c93043b8da326527824887dd diff --git a/patch-db-macro-internals/src/lib.rs b/patch-db-macro-internals/src/lib.rs index 727f97b..3f62b9e 100644 --- a/patch-db-macro-internals/src/lib.rs +++ b/patch-db-macro-internals/src/lib.rs @@ -239,23 +239,23 @@ fn impl_fns(children: &[ChildInfo]) -> Fns { if optional { impl_fns.extend(quote_spanned! { name.span() => #vis fn #name (&self) -> patch_db::OptionModel<#model_ty> { - as patch_db::Model>::new((&**self) #accessor .clone()) + as patch_db::Model>::new((**self) #accessor .clone()) } }); impl_mut_fns.extend(quote_spanned! { name.span() => - #vis fn #name (&self) -> patch_db::OptionModelMut<'a, #model_mut_ty> { - as patch_db::ModelMut<'a>>::new(&mut (&mut **self) #accessor) + #vis fn #name (&'a mut self) -> patch_db::OptionModelMut<'a, #model_mut_ty> { + as patch_db::ModelMut<'a>>::new(&mut (**self) #accessor) } }); } else { impl_fns.extend(quote_spanned! { name.span() => #vis fn #name (&self) -> #model_ty { - <#model_ty as patch_db::Model>::new((&**self) #accessor .clone()) + <#model_ty as patch_db::Model>::new((**self) #accessor .clone()) } }); impl_mut_fns.extend(quote_spanned! { name.span() => - #vis fn #name (&mut self) -> #model_mut_ty { - <#model_mut_ty as patch_db::ModelMut<'a>>::new(&mut (&mut **self) #accessor) + #vis fn #name (&'a mut self) -> #model_mut_ty { + <#model_mut_ty as patch_db::ModelMut<'a>>::new(&mut (**self) #accessor) } }); } diff --git a/patch-db/src/store.rs b/patch-db/src/store.rs index afa226d..6a70003 100644 --- a/patch-db/src/store.rs +++ b/patch-db/src/store.rs @@ -6,7 +6,7 @@ use std::path::{Path, PathBuf}; use std::sync::Arc; use fd_lock_rs::FdLock; -use imbl_value::Value; +use imbl_value::{InternedString, Value}; use json_patch::PatchError; use json_ptr::{JsonPointer, SegList}; use lazy_static::lazy_static; @@ -159,7 +159,7 @@ impl Store { pub(crate) fn keys, V: SegList>( &self, ptr: &JsonPointer, - ) -> BTreeSet> { + ) -> BTreeSet { match ptr.get(&self.persistent).unwrap_or(&Value::Null) { Value::Object(o) => o.keys().cloned().collect(), _ => BTreeSet::new(), @@ -326,7 +326,7 @@ impl PatchDb { pub async fn keys, V: SegList>( &self, ptr: &JsonPointer, - ) -> BTreeSet> { + ) -> BTreeSet { self.store.read().await.keys(ptr) } pub async fn get_value, V: SegList>(&self, ptr: &JsonPointer) -> Value { diff --git a/patch-db/src/test.rs b/patch-db/src/test.rs index 6327afc..ff5bf71 100644 --- a/patch-db/src/test.rs +++ b/patch-db/src/test.rs @@ -1,14 +1,14 @@ use std::future::Future; use std::sync::Arc; +use imbl_value::Value; use json_ptr::JsonPointer; use patch_db::{HasModel, PatchDb, Revision}; use proptest::prelude::*; -use serde_json::Value; use tokio::fs; use tokio::runtime::Builder; -use crate::{self as patch_db, DbHandle, LockType}; +use crate::{self as patch_db}; async fn init_db(db_name: String) -> PatchDb { cleanup_db(&db_name).await; @@ -45,23 +45,10 @@ async fn basic() { let db = init_db("test.db".to_string()).await; let ptr: JsonPointer = "/b/b".parse().unwrap(); let mut get_res: Value = db.get(&ptr).await.unwrap(); - assert_eq!(get_res, 1); + assert_eq!(get_res.as_u64(), Some(1)); db.put(&ptr, "hello").await.unwrap(); get_res = db.get(&ptr).await.unwrap(); - assert_eq!(get_res, "hello"); - cleanup_db("test.db").await; -} - -#[tokio::test] -async fn transaction() { - let db = init_db("test.db".to_string()).await; - let mut handle = db.handle(); - let mut tx = handle.begin().await.unwrap(); - let ptr: JsonPointer = "/b/b".parse().unwrap(); - tx.put(&ptr, &(2 as usize)).await.unwrap(); - tx.put(&ptr, &(1 as usize)).await.unwrap(); - let _res = tx.commit().await.unwrap(); - println!("res = {:?}", _res); + assert_eq!(get_res.as_str(), Some("hello")); cleanup_db("test.db").await; } @@ -100,16 +87,3 @@ pub struct Child { #[derive(Debug, serde::Deserialize, serde::Serialize, HasModel)] pub struct NewType(Option>); - -#[tokio::test] -async fn locks_dropped_from_enforcer_on_tx_save() { - let db = init_db("test.db".to_string()).await; - let mut handle = db.handle(); - let mut tx = handle.begin().await.unwrap(); - let ptr_a: JsonPointer = "/a".parse().unwrap(); - let ptr_b: JsonPointer = "/b".parse().unwrap(); - tx.lock(ptr_b.into(), LockType::Write).await.unwrap(); - tx.save().await.unwrap(); - handle.lock(ptr_a.into(), LockType::Write).await.unwrap(); - cleanup_db("test.db").await; -}