Skip to content

Commit 76d411e

Browse files
committed
refactor: rename TestEnvironment to TestContext and update all variables
- Rename TestEnvironment struct and related types to TestContext - Update file name from environment.rs to context.rs - Rename all function parameters from test_env to test_context - Update variable assignments from env to test_context - Update documentation and comments to reflect new naming - Remove completed refactor document This change resolves naming conflicts with planned deployment environment features and improves code clarity by distinguishing between test infrastructure context and deployment environments.
1 parent 6ba3c9e commit 76d411e

15 files changed

+490
-239
lines changed

docs/refactors/testenvironment-to-testcontext.md

Lines changed: 0 additions & 120 deletions
This file was deleted.

src/bin/e2e_config_tests.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ use torrust_tracker_deploy::e2e::tasks::run_configure_command::run_configure_com
5151
use tracing::{error, info};
5252

5353
use torrust_tracker_deploy::config::InstanceName;
54-
use torrust_tracker_deploy::e2e::environment::{TestEnvironment, TestEnvironmentType};
54+
use torrust_tracker_deploy::e2e::context::{TestContext, TestContextType};
5555
use torrust_tracker_deploy::e2e::tasks::{
5656
container::{
5757
cleanup_infrastructure::cleanup_infrastructure,
@@ -120,19 +120,19 @@ pub async fn main() -> Result<()> {
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 env = TestEnvironment::initialized(
123+
let test_context = TestContext::initialized(
124124
false,
125125
cli.templates_dir,
126126
&ssh_user,
127127
instance_name,
128128
ssh_private_key_path,
129129
ssh_public_key_path,
130-
TestEnvironmentType::Container,
130+
TestContextType::Container,
131131
)?;
132132

133-
preflight_cleanup::cleanup_lingering_resources(&env)?;
133+
preflight_cleanup::cleanup_lingering_resources(&test_context)?;
134134

135-
let test_result = run_configuration_tests(&env).await;
135+
let test_result = run_configuration_tests(&test_context).await;
136136

137137
let test_duration = test_start.elapsed();
138138

@@ -166,19 +166,19 @@ pub async fn main() -> Result<()> {
166166
}
167167

168168
/// Run the complete configuration tests using extracted tasks
169-
async fn run_configuration_tests(test_env: &TestEnvironment) -> Result<()> {
169+
async fn run_configuration_tests(test_context: &TestContext) -> Result<()> {
170170
info!("Starting configuration tests with Docker container");
171171

172172
// Step 1: Run provision simulation (includes container setup and SSH connectivity)
173-
let running_container = run_provision_simulation(test_env).await?;
173+
let running_container = run_provision_simulation(test_context).await?;
174174

175175
// Step 2: Run Ansible configuration
176-
run_configure_command(test_env)?;
176+
run_configure_command(test_context)?;
177177

178178
// Step 3: Run configuration validation
179179
run_configuration_validation(
180180
running_container.ssh_socket_addr(),
181-
&test_env.config.ssh_credentials,
181+
&test_context.config.ssh_credentials,
182182
)
183183
.await?;
184184

src/bin/e2e_provision_tests.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use tracing::{error, info};
2323

2424
// Import E2E testing infrastructure
2525
use torrust_tracker_deploy::config::InstanceName;
26-
use torrust_tracker_deploy::e2e::environment::{TestEnvironment, TestEnvironmentType};
26+
use torrust_tracker_deploy::e2e::context::{TestContext, TestContextType};
2727
use torrust_tracker_deploy::e2e::tasks::{
2828
preflight_cleanup::cleanup_lingering_resources,
2929
virtual_machine::{
@@ -104,24 +104,24 @@ pub async fn main() -> Result<()> {
104104
let ssh_private_key_path = std::path::PathBuf::from("fixtures/testing_rsa");
105105
let ssh_public_key_path = std::path::PathBuf::from("fixtures/testing_rsa.pub");
106106

107-
let env = TestEnvironment::initialized(
107+
let test_context = TestContext::initialized(
108108
cli.keep,
109109
cli.templates_dir,
110110
&ssh_user,
111111
instance_name,
112112
ssh_private_key_path,
113113
ssh_public_key_path,
114-
TestEnvironmentType::VirtualMachine,
114+
TestContextType::VirtualMachine,
115115
)?;
116116

117117
// Perform pre-flight cleanup to remove any lingering resources from interrupted tests
118-
cleanup_lingering_resources(&env)?;
118+
cleanup_lingering_resources(&test_context)?;
119119

120120
let test_start = Instant::now();
121121

122-
let provision_result = run_provisioning_test(&env).await;
122+
let provision_result = run_provisioning_test(&test_context).await;
123123

124-
cleanup_infrastructure(&env);
124+
cleanup_infrastructure(&test_context);
125125

126126
let test_duration = test_start.elapsed();
127127

@@ -165,7 +165,7 @@ pub async fn main() -> Result<()> {
165165
/// 2. **Basic Validation**: Verifies infrastructure is ready (cloud-init completed)
166166
///
167167
/// Returns the provisioned instance IP address on success.
168-
async fn run_provisioning_test(env: &TestEnvironment) -> Result<IpAddr> {
168+
async fn run_provisioning_test(env: &TestContext) -> Result<IpAddr> {
169169
info!(
170170
test_type = "provision_only",
171171
workflow = "infrastructure_provisioning",

src/bin/e2e_tests_full.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use tracing::{error, info};
2828

2929
// Import E2E testing infrastructure
3030
use torrust_tracker_deploy::config::InstanceName;
31-
use torrust_tracker_deploy::e2e::environment::{TestEnvironment, TestEnvironmentType};
31+
use torrust_tracker_deploy::e2e::context::{TestContext, TestContextType};
3232
use torrust_tracker_deploy::e2e::tasks::{
3333
preflight_cleanup::cleanup_lingering_resources,
3434
run_configure_command::run_configure_command,
@@ -103,29 +103,29 @@ pub async fn main() -> Result<()> {
103103
let ssh_private_key_path = std::path::PathBuf::from("fixtures/testing_rsa");
104104
let ssh_public_key_path = std::path::PathBuf::from("fixtures/testing_rsa.pub");
105105

106-
let env = TestEnvironment::initialized(
106+
let test_context = TestContext::initialized(
107107
cli.keep,
108108
cli.templates_dir,
109109
&ssh_user,
110110
instance_name,
111111
ssh_private_key_path,
112112
ssh_public_key_path,
113-
TestEnvironmentType::VirtualMachine,
113+
TestContextType::VirtualMachine,
114114
)?;
115115

116116
// Perform pre-flight cleanup to remove any lingering resources from interrupted tests
117-
cleanup_lingering_resources(&env)?;
117+
cleanup_lingering_resources(&test_context)?;
118118

119119
let test_start = Instant::now();
120120

121-
let deployment_result = run_full_deployment_test(&env).await;
121+
let deployment_result = run_full_deployment_test(&test_context).await;
122122

123123
let validation_result = match &deployment_result {
124-
Ok(instance_ip) => run_test_command(&env, instance_ip).await,
124+
Ok(instance_ip) => run_test_command(&test_context, instance_ip).await,
125125
Err(_) => Ok(()), // Skip validation if deployment failed
126126
};
127127

128-
cleanup_infrastructure(&env);
128+
cleanup_infrastructure(&test_context);
129129

130130
let test_duration = test_start.elapsed();
131131

@@ -176,7 +176,7 @@ pub async fn main() -> Result<()> {
176176
}
177177
}
178178

179-
async fn run_full_deployment_test(env: &TestEnvironment) -> Result<IpAddr> {
179+
async fn run_full_deployment_test(env: &TestContext) -> Result<IpAddr> {
180180
info!(
181181
test_type = "full_deployment",
182182
workflow = "template_based",

0 commit comments

Comments
 (0)