diff --git a/src/environment.rs b/src/environment.rs index 3de6e0b..fc4ff38 100644 --- a/src/environment.rs +++ b/src/environment.rs @@ -23,8 +23,8 @@ pub trait Environment { /// And the config file's path to this environment if it's find, it's defined /// by the `env_config_file` field in the root config toml, and the default /// value is `config.toml`. - async fn start(&self, mode: &str, config: Option) -> Self::DB; + async fn start(&self, env: &str, config: Option) -> Self::DB; /// Stop one [`Database`]. - async fn stop(&self, mode: &str, database: Self::DB); + async fn stop(&self, env: &str, database: Self::DB); } diff --git a/src/runner.rs b/src/runner.rs index 3ef8bc2..1cc4c63 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -30,7 +30,7 @@ use crate::{config::Config, environment::Environment}; /// For more detailed explaination, refer to crate level documentment. pub struct Runner { config: Config, - env: Arc, + env_controller: Arc, } impl Runner { @@ -53,21 +53,26 @@ impl Runner { Ok(Self { config, - env: Arc::new(env), + env_controller: Arc::new(env), }) } pub async fn new_with_config(config: Config, env: E) -> Result { Ok(Self { config, - env: Arc::new(env), + env_controller: Arc::new(env), }) } pub async fn run(&self) -> Result<()> { let environments = self.collect_env().await?; for env in environments { - self.run_env(env).await?; + // todo: read env config + let db = self.env_controller.start(&env, None).await; + if let Err(e) = self.run_env(&env, &db).await { + println!("Environment {} run failed with error {:?}", env, e); + } + self.env_controller.stop(&env, db).await; } Ok(()) @@ -87,10 +92,8 @@ impl Runner { Ok(result) } - async fn run_env(&self, env: String) -> Result<()> { - // todo: read env config - let db = self.env.start(&env, None).await; - let case_paths = self.collect_case_paths(&env).await?; + async fn run_env(&self, env: &str, db: &E::DB) -> Result<()> { + let case_paths = self.collect_case_paths(env).await?; let mut diff_cases = vec![]; let start = Instant::now(); for path in case_paths { @@ -100,7 +103,7 @@ impl Runner { let mut output_file = Self::open_output_file(&output_path).await?; let timer = Instant::now(); - case.execute(&db, &mut output_file).await?; + case.execute(db, &mut output_file).await?; let elapsed = timer.elapsed(); output_file.flush().await?;