Skip to content

Commit 06524ee

Browse files
committed
feat: update E2E binaries to use Environment entities
- Replace hardcoded instance names with Environment entity auto-generation - Change CLI from --templates-dir to --environment parameter - Update all three E2E binaries (config, provision, full) with environment-specific configuration - Add environment-specific default names for isolation: - e2e-config for config tests - e2e-provision for provision tests - e2e-full for full tests - Fix missing panic documentation in e2e-provision-tests - All tests passing with new environment-based infrastructure This enables multiple concurrent test environments without conflicts.
1 parent 4c92442 commit 06524ee

File tree

4 files changed

+124
-48
lines changed

4 files changed

+124
-48
lines changed

docs/issues/multi-environment-support.md

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,32 @@ pub mod environment_name;
128128
// ... existing modules
129129
```
130130

131-
### Step 4: Update E2E Binaries
131+
### Step 4: Update E2E Binaries ✅ COMPLETED
132132

133133
**Files to Modify**:
134134

135-
- `src/bin/e2e_provision_tests.rs`
136-
- `src/bin/e2e_config_tests.rs`
137-
- `src/bin/e2e_tests_full.rs`
135+
- `src/bin/e2e_provision_tests.rs`
136+
- `src/bin/e2e_config_tests.rs`
137+
- `src/bin/e2e_tests_full.rs`
138138

139139
**Requirements**:
140140

141-
- Create Environment instances in each binary
142-
- Use environment-specific configurations
143-
- Maintain existing CLI argument compatibility where possible
141+
- ✅ Create Environment instances in each binary
142+
- ✅ Use environment-specific configurations
143+
- ✅ Replace hardcoded instance names with Environment entity
144+
- ✅ Update CLI arguments from `--templates-dir` to `--environment`
145+
- ✅ Update help text and documentation
146+
147+
**Implementation Summary**:
148+
149+
Each binary now:
150+
151+
- Accepts `--environment` parameter instead of `--templates-dir`
152+
- Creates Environment entity with auto-generated paths and instance names
153+
- Uses different default environment names for isolation:
154+
- `e2e-config` for config tests
155+
- `e2e-provision` for provision tests
156+
- `e2e-full` for full tests
144157

145158
**Example for e2e_config_tests.rs**:
146159

src/bin/e2e_config_tests.rs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
//! Run with custom options:
1717
//!
1818
//! ```bash
19-
//! # Use custom templates directory
20-
//! cargo run --bin e2e-config-tests -- --templates-dir ./custom/templates
19+
//! # Use specific environment name
20+
//! cargo run --bin e2e-config-tests -- --environment e2e-staging
2121
//!
22-
//! # Change logging format
22+
//! # Change logging format
2323
//! cargo run --bin e2e-config-tests -- --log-format json
2424
//!
2525
//! # Show help
@@ -50,7 +50,7 @@ use std::time::Instant;
5050
use torrust_tracker_deploy::e2e::tasks::run_configure_command::run_configure_command;
5151
use tracing::{error, info};
5252

53-
use torrust_tracker_deploy::config::InstanceName;
53+
use torrust_tracker_deploy::domain::{Environment, EnvironmentName};
5454
use torrust_tracker_deploy::e2e::context::{TestContext, TestContextType};
5555
use torrust_tracker_deploy::e2e::tasks::{
5656
container::{
@@ -67,9 +67,9 @@ use torrust_tracker_deploy::shared::Username;
6767
#[command(name = "e2e-config-tests")]
6868
#[command(about = "E2E configuration tests for Torrust Tracker Deploy using Docker containers")]
6969
struct CliArgs {
70-
/// Templates directory path (default: ./data/templates)
71-
#[arg(long, default_value = "./data/templates")]
72-
templates_dir: String,
70+
/// Environment name for deployment testing (e.g., "e2e-config", "staging"). This determines the instance name and directory structure.
71+
#[arg(long, default_value = "e2e-config")]
72+
environment: String,
7373

7474
/// Logging format to use
7575
#[arg(
@@ -106,25 +106,35 @@ pub async fn main() -> Result<()> {
106106
info!(
107107
application = "torrust_tracker_deploy",
108108
test_suite = "e2e_config_tests",
109+
environment = %cli.environment,
109110
log_format = ?cli.log_format,
110111
"Starting E2E configuration tests with Docker containers"
111112
);
112113

113114
let test_start = Instant::now();
114115

115-
let instance_name =
116-
InstanceName::new("torrust-tracker-vm".to_string()).expect("Valid hardcoded instance name");
117-
118-
let ssh_user = Username::new("torrust").expect("Valid hardcoded username");
116+
// Create Environment entity from CLI argument
117+
let env_name = EnvironmentName::new(&cli.environment)
118+
.map_err(|e| anyhow::anyhow!("Invalid environment name '{}': {}", cli.environment, e))?;
119119

120120
let ssh_private_key_path = std::path::PathBuf::from("fixtures/testing_rsa");
121121
let ssh_public_key_path = std::path::PathBuf::from("fixtures/testing_rsa.pub");
122122

123+
let environment = Environment::new(
124+
env_name,
125+
ssh_private_key_path.clone(),
126+
ssh_public_key_path.clone(),
127+
);
128+
129+
let ssh_user = Username::new("torrust").expect("Valid hardcoded username");
130+
131+
// Extract values from Environment entity for TestContext
132+
// TODO: Update TestContext to accept Environment entity directly
123133
let test_context = TestContext::initialized(
124134
false,
125-
cli.templates_dir,
135+
environment.templates_dir(),
126136
&ssh_user,
127-
instance_name,
137+
environment.instance_name.clone(),
128138
ssh_private_key_path,
129139
ssh_public_key_path,
130140
TestContextType::Container,

src/bin/e2e_provision_tests.rs

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,30 @@
55
//! is properly provisioned and ready for configuration, but does NOT attempt
66
//! to configure or install software.
77
//!
8+
//! ## Usage
9+
//!
10+
//! Run the E2E provisioning tests:
11+
//!
12+
//! ```bash
13+
//! cargo run --bin e2e-provision-tests
14+
//! ```
15+
//!
16+
//! Run with custom options:
17+
//!
18+
//! ```bash
19+
//! # Use specific environment name
20+
//! cargo run --bin e2e-provision-tests -- --environment e2e-staging
21+
//!
22+
//! # Keep test environment after completion (for debugging)
23+
//! cargo run --bin e2e-provision-tests -- --keep
24+
//!
25+
//! # Change logging format
26+
//! cargo run --bin e2e-provision-tests -- --log-format json
27+
//!
28+
//! # Show help
29+
//! cargo run --bin e2e-provision-tests -- --help
30+
//! ```
31+
//!
832
//! ## Test Workflow
933
//!
1034
//! 1. **Preflight cleanup** - Remove any lingering test resources
@@ -22,7 +46,7 @@ use std::time::Instant;
2246
use tracing::{error, info};
2347

2448
// Import E2E testing infrastructure
25-
use torrust_tracker_deploy::config::InstanceName;
49+
use torrust_tracker_deploy::domain::{Environment, EnvironmentName};
2650
use torrust_tracker_deploy::e2e::context::{TestContext, TestContextType};
2751
use torrust_tracker_deploy::e2e::tasks::{
2852
preflight_cleanup::cleanup_lingering_resources,
@@ -42,9 +66,9 @@ struct Cli {
4266
#[arg(long)]
4367
keep: bool,
4468

45-
/// Templates directory path (default: ./data/templates)
46-
#[arg(long, default_value = "./data/templates")]
47-
templates_dir: String,
69+
/// Environment name for deployment testing (e.g., "e2e-provision", "staging"). This determines the instance name and directory structure.
70+
#[arg(long, default_value = "e2e-provision")]
71+
environment: String,
4872

4973
/// Logging format to use
5074
#[arg(
@@ -69,18 +93,16 @@ struct Cli {
6993
/// # Errors
7094
///
7195
/// This function may return errors in the following cases:
96+
/// - Invalid environment name provided via CLI
7297
/// - Test environment setup fails
7398
/// - Pre-flight cleanup encounters issues
7499
/// - Infrastructure provisioning fails
75100
/// - Cleanup operations fail
76101
///
77102
/// # Panics
78103
///
79-
/// May panic if the hardcoded instance name "torrust-tracker-vm" is invalid,
104+
/// This function may panic if the hardcoded username "torrust" is invalid,
80105
/// which should never happen in normal operation.
81-
///
82-
/// May panic during the match statement if unexpected error combinations occur
83-
/// that are not handled by the current error handling logic.
84106
#[tokio::main]
85107
pub async fn main() -> Result<()> {
86108
let cli = Cli::parse();
@@ -95,20 +117,23 @@ pub async fn main() -> Result<()> {
95117
"Starting E2E provisioning tests"
96118
);
97119

98-
// Instance name for the test environment - not user configurable for now
99-
let instance_name =
100-
InstanceName::new("torrust-tracker-vm".to_string()).expect("Valid hardcoded instance name");
101-
102-
let ssh_user = Username::new("torrust").expect("Valid hardcoded username");
103-
120+
// Create environment entity from CLI input
121+
let environment_name = EnvironmentName::new(cli.environment)?;
104122
let ssh_private_key_path = std::path::PathBuf::from("fixtures/testing_rsa");
105123
let ssh_public_key_path = std::path::PathBuf::from("fixtures/testing_rsa.pub");
124+
let environment = Environment::new(
125+
environment_name,
126+
ssh_private_key_path.clone(),
127+
ssh_public_key_path.clone(),
128+
);
129+
130+
let ssh_user = Username::new("torrust").expect("Valid hardcoded username");
106131

107132
let test_context = TestContext::initialized(
108133
cli.keep,
109-
cli.templates_dir,
134+
environment.data_dir.to_string_lossy().to_string(),
110135
&ssh_user,
111-
instance_name,
136+
environment.instance_name.clone(),
112137
ssh_private_key_path,
113138
ssh_public_key_path,
114139
TestContextType::VirtualMachine,

src/bin/e2e_tests_full.rs

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,30 @@
99
//! - `cargo run --bin e2e-provision-tests` - Infrastructure provisioning only
1010
//! - `cargo run --bin e2e-config-tests` - Configuration and software installation
1111
//!
12+
//! ## Usage
13+
//!
14+
//! Run the full E2E test suite:
15+
//!
16+
//! ```bash
17+
//! cargo run --bin e2e-tests-full
18+
//! ```
19+
//!
20+
//! Run with custom options:
21+
//!
22+
//! ```bash
23+
//! # Use specific environment name
24+
//! cargo run --bin e2e-tests-full -- --environment e2e-staging
25+
//!
26+
//! # Keep test environment after completion (for debugging)
27+
//! cargo run --bin e2e-tests-full -- --keep
28+
//!
29+
//! # Change logging format
30+
//! cargo run --bin e2e-tests-full -- --log-format json
31+
//!
32+
//! # Show help
33+
//! cargo run --bin e2e-tests-full -- --help
34+
//! ```
35+
//!
1236
//! ## Test Workflow
1337
//!
1438
//! 1. **Preflight cleanup** - Remove any lingering test resources
@@ -27,7 +51,7 @@ use std::time::Instant;
2751
use tracing::{error, info};
2852

2953
// Import E2E testing infrastructure
30-
use torrust_tracker_deploy::config::InstanceName;
54+
use torrust_tracker_deploy::domain::{Environment, EnvironmentName};
3155
use torrust_tracker_deploy::e2e::context::{TestContext, TestContextType};
3256
use torrust_tracker_deploy::e2e::tasks::{
3357
preflight_cleanup::cleanup_lingering_resources,
@@ -49,9 +73,9 @@ struct Cli {
4973
#[arg(long)]
5074
keep: bool,
5175

52-
/// Templates directory path (default: ./data/templates)
53-
#[arg(long, default_value = "./data/templates")]
54-
templates_dir: String,
76+
/// Environment name for deployment testing (e.g., "e2e-full", "staging"). This determines the instance name and directory structure.
77+
#[arg(long, default_value = "e2e-full")]
78+
environment: String,
5579

5680
/// Logging format to use
5781
#[arg(
@@ -70,6 +94,7 @@ struct Cli {
7094
/// # Errors
7195
///
7296
/// Returns an error if:
97+
/// - Invalid environment name provided via CLI
7398
/// - Pre-flight cleanup fails
7499
/// - Infrastructure provisioning fails
75100
/// - Service configuration fails
@@ -94,20 +119,23 @@ pub async fn main() -> Result<()> {
94119
"Starting E2E tests"
95120
);
96121

97-
// Instance name for the test environment - not user configurable for now
98-
let instance_name =
99-
InstanceName::new("torrust-tracker-vm".to_string()).expect("Valid hardcoded instance name");
100-
101-
let ssh_user = Username::new("torrust").expect("Valid hardcoded username");
102-
122+
// Create environment entity from CLI input
123+
let environment_name = EnvironmentName::new(cli.environment)?;
103124
let ssh_private_key_path = std::path::PathBuf::from("fixtures/testing_rsa");
104125
let ssh_public_key_path = std::path::PathBuf::from("fixtures/testing_rsa.pub");
126+
let environment = Environment::new(
127+
environment_name,
128+
ssh_private_key_path.clone(),
129+
ssh_public_key_path.clone(),
130+
);
131+
132+
let ssh_user = Username::new("torrust").expect("Valid hardcoded username");
105133

106134
let test_context = TestContext::initialized(
107135
cli.keep,
108-
cli.templates_dir,
136+
environment.data_dir.to_string_lossy().to_string(),
109137
&ssh_user,
110-
instance_name,
138+
environment.instance_name.clone(),
111139
ssh_private_key_path,
112140
ssh_public_key_path,
113141
TestContextType::VirtualMachine,

0 commit comments

Comments
 (0)