pub mod database_test_utils;
pub mod redis_test_utils;
use oxcache::{config::OxcacheConfig as Config, Cache};
use redis_test_utils::{
is_redis_available_default, wait_for_redis as redis_test_wait_for_redis,
wait_for_redis_cluster as redis_test_wait_for_redis_cluster,
wait_for_sentinel as redis_test_wait_for_sentinel,
};
use std::sync::Once;
use tracing_subscriber::fmt::format::FmtSpan;
use tracing_subscriber::EnvFilter;
static INIT: Once = Once::new();
pub fn setup_logging() {
INIT.call_once(|| {
tracing_subscriber::fmt()
.with_span_events(FmtSpan::CLOSE)
.with_env_filter(EnvFilter::new("debug"))
.try_init()
.ok();
});
}
#[allow(dead_code)]
pub async fn setup_cache(_config: Config) -> Cache<String, Vec<u8>> {
setup_logging();
Cache::new()
.await
.unwrap_or_else(|e| panic!("Failed to create memory cache: {}", e))
}
#[allow(dead_code)]
pub async fn is_redis_available() -> bool {
is_redis_available_default().await
}
#[allow(dead_code)]
pub async fn wait_for_redis(url: &str) -> bool {
redis_test_wait_for_redis(url).await
}
#[allow(dead_code)]
pub async fn wait_for_redis_url(url: &str) -> bool {
wait_for_redis(url).await
}
#[allow(dead_code)]
pub async fn wait_for_redis_cluster(urls: &[&str]) -> bool {
redis_test_wait_for_redis_cluster(urls).await
}
#[allow(dead_code)]
pub async fn wait_for_sentinel() -> bool {
redis_test_wait_for_sentinel().await
}
#[allow(dead_code)]
pub fn generate_unique_service_name(base: &str) -> String {
format!("{}_{}", base, uuid::Uuid::new_v4().simple())
}
#[allow(dead_code)]
pub async fn cleanup_service(service_name: &str) {
tokio::fs::remove_file(format!("{}_wal.db", service_name))
.await
.ok();
tokio::fs::remove_file(format!("{}.db", service_name))
.await
.ok();
}