vdev/commands/compose_tests/
test.rs

1use anyhow::{Result, bail};
2
3use crate::testing::{
4    config::ComposeTestConfig,
5    integration::{ComposeTest, ComposeTestLocalConfig},
6    state::EnvsDir,
7};
8
9pub fn exec(
10    local_config: ComposeTestLocalConfig,
11    integration: &str,
12    environment: Option<&String>,
13    build_all: bool,
14    retries: u8,
15    args: &[String],
16) -> Result<()> {
17    let (_test_dir, config) = ComposeTestConfig::load(local_config.directory, integration)?;
18    let envs = config.environments();
19
20    let active = EnvsDir::new(integration).active()?;
21    debug!("Active environment: {environment:#?}");
22
23    match (environment, &active) {
24        (Some(environment), Some(active)) if environment != active => {
25            bail!("Requested environment {environment:?} does not match active one {active:?}")
26        }
27        (Some(environment), _) => {
28            ComposeTest::generate(local_config, integration, environment, build_all, retries)?
29                .test(args.to_owned())
30        }
31        (None, Some(active)) => {
32            ComposeTest::generate(local_config, integration, active, build_all, retries)?
33                .test(args.to_owned())
34        }
35        (None, None) => {
36            for env_name in envs.keys() {
37                ComposeTest::generate(local_config, integration, env_name, build_all, retries)?
38                    .test(args.to_owned())?;
39            }
40            Ok(())
41        }
42    }
43}