use collab_persistence::kv::rocks_kv::RocksCollabDB; use flowy_document2::manager::DocumentUser; use parking_lot::Once; use std::sync::Arc; use tempfile::TempDir; use tracing_subscriber::{fmt::Subscriber, util::SubscriberInitExt, EnvFilter}; pub struct FakeUser { kv: Arc, } impl FakeUser { pub fn new() -> Self { Self { kv: db() } } } impl DocumentUser for FakeUser { fn user_id(&self) -> Result { Ok(1) } fn token(&self) -> Result { Ok("1".to_string()) } fn kv_db(&self) -> Result, flowy_error::FlowyError> { Ok(self.kv.clone()) } } pub fn db() -> Arc { static START: Once = Once::new(); START.call_once(|| { std::env::set_var("RUST_LOG", "collab_persistence=trace"); let subscriber = Subscriber::builder() .with_env_filter(EnvFilter::from_default_env()) .with_ansi(true) .finish(); subscriber.try_init().unwrap(); }); let tempdir = TempDir::new().unwrap(); let path = tempdir.into_path(); Arc::new(RocksCollabDB::open(path).unwrap()) }