vdev/commands/compose_tests/
show.rs1use anyhow::Result;
2
3use crate::testing::{config::ComposeTestConfig, config::Environment, state};
4
5pub fn exec(integration: Option<&String>, path: &str) -> Result<()> {
6 match integration {
7 None => {
8 let entries = ComposeTestConfig::collect_all(path)?;
9 let width = entries
10 .keys()
11 .fold(16, |width, entry| width.max(entry.len()));
12 println!("{:width$} Environment Name(s)", "Integration Name");
13 println!("{:width$} -------------------", "----------------");
14 for (integration, config) in entries {
15 let envs_dir = state::EnvsDir::new(&integration);
16 let active_env = envs_dir.active()?;
17 let environments = config
18 .environments()
19 .keys()
20 .map(|environment| format(active_env.as_ref(), environment))
21 .collect::<Vec<_>>()
22 .join(" ");
23 println!("{integration:width$} {environments}");
24 }
25 }
26 Some(integration) => {
27 let (_test_dir, config) = ComposeTestConfig::load(path, integration)?;
28 let envs_dir = state::EnvsDir::new(integration);
29 let active_env = envs_dir.active()?;
30
31 if let Some(args) = &config.args {
32 println!("Test args: {}", args.join(" "));
33 } else {
34 println!("Test args: N/A");
35 }
36
37 if config.features.is_empty() {
38 println!("Features: N/A");
39 } else {
40 println!("Features: {}", config.features.join(","));
41 }
42
43 println!(
44 "Test filter: {}",
45 config.test_filter.as_deref().unwrap_or("N/A")
46 );
47
48 println!("Environment:");
49 print_env(" ", &config.env);
50 println!("Runner:");
51 println!(" Environment:");
52 print_env(" ", &config.runner.env);
53 println!(" Volumes:");
54 if config.runner.volumes.is_empty() {
55 println!(" N/A");
56 } else {
57 for (target, mount) in &config.runner.volumes {
58 println!(" {target} => {mount}");
59 }
60 }
61 println!(
62 " Needs docker socket: {}",
63 config.runner.needs_docker_socket
64 );
65
66 println!("Environments:");
67 for environment in config.environments().keys() {
68 println!(" {}", format(active_env.as_ref(), environment));
69 }
70 }
71 }
72 Ok(())
73}
74
75fn format(active_env: Option<&String>, environment: &str) -> String {
76 match active_env {
77 Some(active) if active == environment => format!("{environment} (active)"),
78 _ => environment.into(),
79 }
80}
81
82fn print_env(prefix: &str, environment: &Environment) {
83 if environment.is_empty() {
84 println!("{prefix}N/A");
85 } else {
86 for (key, value) in environment {
87 match value {
88 Some(value) => println!("{prefix}{key}={value:?}"),
89 None => println!("{prefix}{key} (passthrough)"),
90 }
91 }
92 }
93}