From 8b4f27d2c39d1e1f5f1cc455c58800e806ee98d0 Mon Sep 17 00:00:00 2001 From: rtkay123 Date: Sun, 10 Aug 2025 17:29:11 +0200 Subject: build(docker): pseudonyms --- crates/pseudonyms/tests/helpers.rs | 54 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 crates/pseudonyms/tests/helpers.rs (limited to 'crates/pseudonyms/tests/helpers.rs') diff --git a/crates/pseudonyms/tests/helpers.rs b/crates/pseudonyms/tests/helpers.rs new file mode 100644 index 0000000..9f512df --- /dev/null +++ b/crates/pseudonyms/tests/helpers.rs @@ -0,0 +1,54 @@ +use sqlx::PgPool; +use warden_stack::{Configuration, cache::RedisManager}; +use tokio::sync::oneshot; +use tonic::transport::Channel; +use warden_core::pseudonyms::transaction_relationship::mutate_pseudonym_client::MutatePseudonymClient; +use warden_pseudonyms::state::{AppHandle, AppState, Services}; + +use std::sync::Arc; + +pub struct TestApp { + state: AppHandle, + pub mutate: MutatePseudonymClient, +} + +impl TestApp { + pub async fn new(pool: PgPool) -> Self { + let (tx, rx) = oneshot::channel(); + // Set port to 0 so tests can spawn multiple servers on OS assigned ports. + // + let config_path = "pseudonyms.toml"; + + let config = config::Config::builder() + .add_source(config::File::new(config_path, config::FileFormat::Toml)) + .build() + .unwrap(); + + let mut config = config.try_deserialize::().unwrap(); + config.application.port = 0; + + let cache = RedisManager::new(&config.cache).await.unwrap(); + + let services = Services { + postgres: pool, + cache, + }; + + let state = AppHandle(Arc::new(AppState::new(services, config, None).unwrap())); + + dbg!(&state.addr.port()); + + tokio::spawn(warden_pseudonyms::run(state.clone(), tx)); + let port = rx.await.expect("channel to be open"); + let addr = format!("http://[::1]:{port}"); + + let mutation_client = MutatePseudonymClient::connect(addr.to_string()) + .await + .expect("expect server to be running"); + + Self { + state, + mutate: mutation_client, + } + } +} -- cgit v1.2.3