diff --git a/src/data/actor.rs b/src/data/actor.rs index 31cb927..6d2d65a 100644 --- a/src/data/actor.rs +++ b/src/data/actor.rs @@ -57,11 +57,13 @@ impl ActorCache { } pub(crate) async fn add_connection(&self, actor: Actor) -> Result<(), MyError> { + log::debug!("Adding connection: {}", actor.id); self.db.add_connection(actor.id.clone()).await?; self.db.save_actor(actor).await } pub(crate) async fn remove_connection(&self, actor: &Actor) -> Result<(), MyError> { + log::debug!("Removing connection: {}", actor.id); self.db.remove_connection(actor.id.clone()).await } diff --git a/src/db.rs b/src/db.rs index 8955405..d35a992 100644 --- a/src/db.rs +++ b/src/db.rs @@ -194,8 +194,10 @@ impl Inner { impl Db { pub(crate) fn build(config: &Config) -> Result { let db = sled::open(config.sled_path())?; - let restricted_mode = config.restricted_mode(); + Self::build_inner(config.restricted_mode(), db) + } + fn build_inner(restricted_mode: bool, db: sled::Db) -> Result { Ok(Db { inner: Arc::new(Inner { actor_id_actor: db.open_tree("actor-id-actor")?, @@ -621,3 +623,29 @@ fn url_from_ivec(ivec: sled::IVec) -> Option { fn uuid_from_ivec(ivec: sled::IVec) -> Option { Uuid::from_slice(&ivec).ok() } + +#[cfg(test)] +mod tests { + use super::Db; + use activitystreams::url::Url; + use std::future::Future; + + #[test] + fn connect_and_verify() { + run(|db| async move { + let example_actor: Url = "http://example.com/actor".parse().unwrap(); + db.add_connection(example_actor.clone()).await.unwrap(); + assert!(db.is_connected(example_actor).await.unwrap()); + }) + } + + fn run(f: F) + where + F: Fn(Db) -> Fut, + Fut: Future + 'static, + { + let db = + Db::build_inner(true, sled::Config::new().temporary(true).open().unwrap()).unwrap(); + actix_rt::System::new("test").block_on((f)(db)); + } +}