use std::{
process,
sync::atomic::{AtomicU64, Ordering},
};
use eventsourcingdb::{Client, container::Container};
use tokio::sync::OnceCell;
static CONTAINER: OnceCell<Container> = OnceCell::const_new();
pub(super) async fn container() -> &'static Container {
CONTAINER
.get_or_init(|| async {
let image_tag =
std::env::var("EVENTSOURCINGDB_IMAGE_TAG").unwrap_or_else(|_| "latest".to_owned());
Container::builder()
.with_image_tag(&image_tag)
.with_signing_key()
.start()
.await
.expect("the database starts")
})
.await
}
pub(super) async fn client() -> Client {
container()
.await
.get_client()
.await
.expect("the database has a client")
}
pub(super) fn subject_for(name: &str) -> String {
static NEXT: AtomicU64 = AtomicU64::new(0);
format!(
"/test/{name}/{}-{}",
process::id(),
NEXT.fetch_add(1, Ordering::Relaxed),
)
}