shiny_application/
test_application.rs1use crate::Module;
2use shiny_common::context::Context;
3use shiny_common::error::ServiceError;
4use shiny_jobs::Job;
5use std::collections::HashMap;
6use std::sync::Arc;
7
8pub struct TestApplication {
9 jobs: HashMap<String, Arc<dyn Job>>,
10}
11
12impl TestApplication {
13 pub fn new<TClients, TModule>(clients: TClients, module: TModule) -> Self
14 where
15 TModule: Module<Clients = TClients>,
16 {
17 let controllers = module.create(clients);
18
19 TestApplication {
20 jobs: controllers.job.take_jobs().into_iter().collect(),
21 }
22 }
23
24 pub async fn run_job(&self, name: &str, context: &mut Context) -> Result<(), ServiceError> {
25 let Some(job) = self.jobs.get(name) else {
26 panic!("job `{name}` does not exists")
27 };
28 job.execute(context).await?;
29 Ok(())
30 }
31}