1pub mod tracing_capture;
4
5pub use tracing_capture::{tracing_test_lock, SharedBuf, SharedWriter};
6
7use std::sync::Arc;
8
9use async_trait::async_trait;
10use serde_json::Value;
11use soma_application::{
12 provider_registry::Provider, ApplicationPorts, ProviderCall, ProviderError, ProviderOutput,
13 ProviderRegistry, SomaApplication, SomaService,
14};
15use soma_client::SomaClient;
16use soma_config::SomaConfig;
17use soma_provider_core::ProviderCatalog;
18
19struct FixtureProvider {
20 catalog: ProviderCatalog,
21 output: Value,
22}
23
24#[async_trait]
25impl Provider for FixtureProvider {
26 fn catalog(&self) -> ProviderCatalog {
27 self.catalog.clone()
28 }
29
30 async fn call(&self, _call: ProviderCall) -> Result<ProviderOutput, ProviderError> {
31 Ok(ProviderOutput::json(self.output.clone()))
32 }
33}
34
35pub fn application_with_provider(catalog: ProviderCatalog, output: Value) -> Arc<SomaApplication> {
36 let service = SomaService::new(
37 SomaClient::new(&SomaConfig::default()).expect("test Soma client should build"),
38 );
39 let registry = ProviderRegistry::new(vec![Arc::new(FixtureProvider { catalog, output })])
40 .expect("test provider registry should build");
41 Arc::new(SomaApplication::new(
42 Arc::new(service),
43 Arc::new(registry),
44 ApplicationPorts::unavailable(),
45 ))
46}
47
48pub fn default_application() -> Arc<SomaApplication> {
49 default_application_with_ports(ApplicationPorts::unavailable())
50}
51
52pub fn default_application_with_ports(ports: ApplicationPorts) -> Arc<SomaApplication> {
53 let service = SomaService::new(
54 SomaClient::new(&SomaConfig {
55 api_url: String::new(),
56 api_key: "test".into(),
57 ..SomaConfig::default()
58 })
59 .expect("test Soma client should build"),
60 );
61 let registry = soma_application::static_provider_registry(service.clone())
62 .expect("static test provider registry should build");
63 Arc::new(SomaApplication::new(
64 Arc::new(service),
65 Arc::new(registry),
66 ports,
67 ))
68}