diff --git a/src/ctx.rs b/src/ctx.rs index ad60ce4..533cb4f 100644 --- a/src/ctx.rs +++ b/src/ctx.rs @@ -26,95 +26,6 @@ pub trait FullAppContext: std::marker::Send + std::marker::Sync + CloneFullAppCt fn port(&self) -> u32; } -pub trait MinAppContext: std::marker::Send + std::marker::Sync { - fn docker_(&self) -> Arc; - fn results_(&self) -> &ResultStore; - fn port_(&self) -> u32; -} - -impl MinAppContext for Arc { - fn docker_(&self) -> Arc { - self.docker() - } - fn results_(&self) -> &ResultStore { - self.results() - } - fn port_(&self) -> u32 { - self.port() - } -} - -#[derive(Clone)] -pub struct Ctx { - settings: Settings, - db: Database, - results: ResultStore, - docker: Arc, -} - -impl FullAppContext for Ctx { - fn settings(&self) -> &Settings { - &self.settings - } - fn db(&self) -> &Database { - &self.db - } - fn docker(&self) -> Arc { - self.docker.clone() - } - fn results(&self) -> &ResultStore { - &self.results - } - fn port(&self) -> u32 { - self.settings.server.port - } -} - -impl MinAppContext for Ctx { - fn docker_(&self) -> Arc { - self.docker() - } - fn results_(&self) -> &ResultStore { - self.results() - } - fn port_(&self) -> u32 { - self.port() - } -} - -//impl MinAppContext for Arc { -// fn docker_(&self) -> Arc{ -// self.docker_() -// } -// fn results_(&self) -> &ResultStore { -// self.results_() -// } -// fn port_(&self) -> u32 { -// self.port_() -// } -//} -// -//impl FullAppContext for Arc { -// fn settings(&self) -> &Settings { -// self.settings() -// } -// fn db(&self) -> &Database { -// self.db() -// } -// -// fn docker(&self) -> Arc{ -// self.docker() -// } -// fn results(&self) -> &ResultStore { -// self.results() -// } -// fn port(&self) -> u32 { -// self.port() -// } -// -// -//} - pub trait CloneFullAppCtx { fn clone_f(&self) -> Box; } @@ -134,28 +45,65 @@ impl Clone for Box { } } -//pub trait CloneMinAppContext { -// fn clone_fi(&self) -> Box; -//} -// -//impl CloneMinAppContext for T -//where -// T: CloneMinAppContext + Clone + 'static, -//{ -// fn clone_fi(&self) -> Box { -// Box::new(self.clone()) -// } -//} -// -//impl Clone for Box { -// fn clone(&self) -> Self { -// (**self).clone_fi() -// } -//} +pub trait MinAppContext: std::marker::Send + std::marker::Sync { + fn docker_(&self) -> Arc; + fn results_(&self) -> &ResultStore; + fn port_(&self) -> u32; +} + +impl MinAppContext for Arc { + fn docker_(&self) -> Arc { + self.docker() + } + fn results_(&self) -> &ResultStore { + self.results() + } + fn port_(&self) -> u32 { + self.port() + } +} + +#[derive(Clone)] +pub struct DaemonCtx { + settings: Settings, + db: Database, + results: ResultStore, + docker: Arc, +} + +impl FullAppContext for DaemonCtx { + fn settings(&self) -> &Settings { + &self.settings + } + fn db(&self) -> &Database { + &self.db + } + fn docker(&self) -> Arc { + self.docker.clone() + } + fn results(&self) -> &ResultStore { + &self.results + } + fn port(&self) -> u32 { + self.settings.server.port + } +} + +impl MinAppContext for DaemonCtx { + fn docker_(&self) -> Arc { + self.docker() + } + fn results_(&self) -> &ResultStore { + self.results() + } + fn port_(&self) -> u32 { + self.port() + } +} pub type ResultStore = Arc>>>; -impl Ctx { +impl DaemonCtx { pub async fn new(settings: Settings) -> Self { let results = HashMap::default(); let results = Arc::new(RwLock::new(results)); @@ -168,3 +116,32 @@ impl Ctx { } } } + +#[derive(Clone)] +pub struct CliCtx { + results: ResultStore, + docker: Arc, +} + +impl MinAppContext for CliCtx { + fn docker_(&self) -> Arc { + self.docker.clone() + } + fn results_(&self) -> &ResultStore { + &self.results + } + fn port_(&self) -> u32 { + 29130 + } +} + +impl CliCtx { + pub fn new() -> Self { + let results = HashMap::default(); + let results = Arc::new(RwLock::new(results)); + Self { + results, + docker: Arc::new(Docker::new()), + } + } +} diff --git a/src/runner/init_scripts.rs b/src/runner/init_scripts.rs index b9bcc9d..70ce15f 100644 --- a/src/runner/init_scripts.rs +++ b/src/runner/init_scripts.rs @@ -59,14 +59,14 @@ mod tests { use super::*; use crate::docker_compose::DockerCompose; - use crate::{AppMinCtx, Ctx, Settings}; + use crate::{AppMinCtx, DaemonCtx, Settings}; use crate::complaince::suite::Test; #[actix_rt::test] async fn launch_init_containers_works() { let settings = Settings::new().unwrap(); - let ctx = AppMinCtx::new(Arc::new(Ctx::new(settings.clone()).await)); + let ctx = AppMinCtx::new(Arc::new(DaemonCtx::new(settings.clone()).await)); // let base_dir = Path::new(&ctx.settings.repository.base_dir); // let control = base_dir.join("control"); diff --git a/src/runner/suite.rs b/src/runner/suite.rs index 5132acd..489c5cc 100644 --- a/src/runner/suite.rs +++ b/src/runner/suite.rs @@ -172,7 +172,7 @@ mod tests { use crate::complaince::result::Result as CResult; use crate::complaince::suite::Test; - use crate::{AppMinCtx, Ctx, Settings}; + use crate::{AppMinCtx, DaemonCtx, Settings}; use std::sync::Arc; @@ -240,7 +240,7 @@ mod tests { const LOGS: &str = "SUITE RUNNER LOG STRING"; let settings = Settings::new().unwrap(); - let ctx = Ctx::new(settings.clone()).await; + let ctx = DaemonCtx::new(settings.clone()).await; // ctx.docker_ = Arc::new(Testdocker_::new()); let ctx = crate::AppFullCtx::new(Arc::new(ctx));