AppFlowy/frontend/rust-lib/flowy-document2/tests/document/util.rs
Nathan.fooo a9c06632ad
ci: tauri build (#2485)
* ci: tauri build

* ci: tauri build

* chore: update appflowy-collab version

* ci: fix build

* ci: tauri with pnpm

* ci: fix build

* ci: comment out includetime

* chore: add the --quiet option (to only output errors and not warnings) to the configuration file

* ci: enable linux platform

---------

Co-authored-by: qinluhe <qinluhe.twodog@gmail.com>
2023-05-10 13:27:50 +08:00

49 lines
1.1 KiB
Rust

use std::sync::Arc;
use collab_plugins::disk::kv::rocks_kv::RocksCollabDB;
use parking_lot::Once;
use tempfile::TempDir;
use tracing_subscriber::{fmt::Subscriber, util::SubscriberInitExt, EnvFilter};
use flowy_document2::manager::DocumentUser;
pub struct FakeUser {
kv: Arc<RocksCollabDB>,
}
impl FakeUser {
pub fn new() -> Self {
Self { kv: db() }
}
}
impl DocumentUser for FakeUser {
fn user_id(&self) -> Result<i64, flowy_error::FlowyError> {
Ok(1)
}
fn token(&self) -> Result<String, flowy_error::FlowyError> {
Ok("1".to_string())
}
fn kv_db(&self) -> Result<std::sync::Arc<RocksCollabDB>, flowy_error::FlowyError> {
Ok(self.kv.clone())
}
}
pub fn db() -> Arc<RocksCollabDB> {
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())
}