1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use anyhow::{bail, Result};

use crate::testing::{config::ComposeTestConfig, integration::ComposeTestT, state::EnvsDir};

pub fn exec<T: ComposeTestT>(
    integration: &str,
    environment: &Option<String>,
    build_all: bool,
    retries: u8,
    args: &[String],
) -> Result<()> {
    let (_test_dir, config) = ComposeTestConfig::load(T::DIRECTORY, integration)?;
    let envs = config.environments();

    let active = EnvsDir::new(integration).active()?;

    match (&environment, &active) {
        (Some(environment), Some(active)) if environment != active => {
            bail!("Requested environment {environment:?} does not match active one {active:?}")
        }
        (Some(environment), _) => T::test(
            &T::generate(integration, environment, build_all, retries)?,
            args.to_owned(),
        ),
        (None, Some(active)) => T::test(
            &T::generate(integration, active, build_all, retries)?,
            args.to_owned(),
        ),
        (None, None) => {
            for env_name in envs.keys() {
                T::test(
                    &T::generate(integration, env_name, build_all, retries)?,
                    args.to_owned(),
                )?;
            }
            Ok(())
        }
    }
}