aboutsummaryrefslogtreecommitdiffstats
path: root/crates/pseudonyms/tests/helpers.rs
diff options
context:
space:
mode:
authorrtkay123 <dev@kanjala.com>2025-08-10 17:29:11 +0200
committerrtkay123 <dev@kanjala.com>2025-08-10 17:29:11 +0200
commit8b4f27d2c39d1e1f5f1cc455c58800e806ee98d0 (patch)
treeef7e9f9ce3acff22f647184e6cdd1866e3f29823 /crates/pseudonyms/tests/helpers.rs
parent4e070c8205c7039b8b63260976ffc81b5ac67beb (diff)
downloadwarden-8b4f27d2c39d1e1f5f1cc455c58800e806ee98d0.tar.bz2
warden-8b4f27d2c39d1e1f5f1cc455c58800e806ee98d0.zip
build(docker): pseudonyms
Diffstat (limited to 'crates/pseudonyms/tests/helpers.rs')
-rw-r--r--crates/pseudonyms/tests/helpers.rs54
1 files changed, 54 insertions, 0 deletions
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<Channel>,
+}
+
+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::<Configuration>().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,
+ }
+ }
+}