Skip to content

Commit ef0412c

Browse files
committed
refactor: improve function dependencies and method naming in e2e config tests
- Refactor e2e config test functions to inject SocketAddr directly instead of RunningProvisionedContainer - Functions now receive only the ssh_service_socket_addr parameter they actually need - Apply Dependency Inversion Principle and Interface Segregation Principle for cleaner API - Rename RunningProvisionedContainer::ssh_details() to ssh_socket_addr() for clarity - Better type-descriptive naming that immediately indicates return type and purpose - Update documentation examples to reflect new method name This reduces coupling between components and makes functions more focused on their specific requirements, following the Principle of Least Knowledge.
1 parent dd9c68b commit ef0412c

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

src/bin/e2e_config_tests.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ async fn configure_ssh_connectivity(
191191
container: &RunningProvisionedContainer,
192192
test_env: &TestEnvironment,
193193
) -> Result<()> {
194-
let socket_addr = container.ssh_details();
194+
let socket_addr = container.ssh_socket_addr();
195195
let timeouts = ContainerTimeouts::default();
196196
let ssh_wait_action = SshWaitAction::new(timeouts.ssh_ready, 10);
197197
ssh_wait_action
@@ -231,15 +231,15 @@ async fn run_configuration_tests(templates_dir: String, instance_name: InstanceN
231231

232232
// Step 2.5: Run provision simulation to render Ansible templates
233233
info!("Running provision simulation to prepare container configuration");
234-
run_provision_simulation(&running_container, &test_env).await?;
234+
run_provision_simulation(running_container.ssh_socket_addr(), &test_env).await?;
235235

236236
// Step 3: Run configuration tasks (Ansible playbooks)
237237
info!("Running Ansible configuration tasks");
238-
run_ansible_configuration(&running_container, &test_env)?;
238+
run_ansible_configuration(running_container.ssh_socket_addr(), &test_env)?;
239239

240240
// Step 4: Validate deployment
241241
info!("Validating service deployment");
242-
run_deployment_validation(&running_container, &test_env).await?;
242+
run_deployment_validation(running_container.ssh_socket_addr(), &test_env).await?;
243243

244244
// Step 5: Cleanup - transition back to stopped state
245245
cleanup_container(running_container);
@@ -258,13 +258,11 @@ fn cleanup_container(running_container: RunningProvisionedContainer) {
258258

259259
/// Run provision simulation to prepare templates for container configuration
260260
async fn run_provision_simulation(
261-
running_container: &RunningProvisionedContainer,
261+
ssh_service_socket_addr: SocketAddr,
262262
test_env: &TestEnvironment,
263263
) -> Result<()> {
264-
let socket_addr = running_container.ssh_details();
265-
266264
info!(
267-
socket_addr = %socket_addr,
265+
socket_addr = %ssh_service_socket_addr,
268266
"Running provision simulation for container"
269267
);
270268

@@ -282,7 +280,7 @@ async fn run_provision_simulation(
282280
provision_docker_infrastructure(
283281
Arc::clone(&services.ansible_template_renderer),
284282
ssh_credentials,
285-
socket_addr,
283+
ssh_service_socket_addr,
286284
)
287285
.await
288286
.context("Failed to complete Docker infrastructure provision simulation")?;
@@ -297,13 +295,11 @@ async fn run_provision_simulation(
297295

298296
/// Run Ansible configuration tasks on the container
299297
fn run_ansible_configuration(
300-
running_container: &RunningProvisionedContainer,
298+
ssh_service_socket_addr: SocketAddr,
301299
test_env: &TestEnvironment,
302300
) -> Result<()> {
303-
let socket_addr = running_container.ssh_details();
304-
305301
info!(
306-
socket_addr = %socket_addr,
302+
socket_addr = %ssh_service_socket_addr,
307303
"Running Ansible configuration on container"
308304
);
309305

@@ -358,13 +354,11 @@ fn run_ansible_configuration(
358354

359355
/// Run deployment validation tests on the container
360356
async fn run_deployment_validation(
361-
running_container: &RunningProvisionedContainer,
357+
ssh_service_socket_addr: SocketAddr,
362358
test_env: &TestEnvironment,
363359
) -> Result<()> {
364-
let socket_addr = running_container.ssh_details();
365-
366360
info!(
367-
socket_addr = %socket_addr,
361+
socket_addr = %ssh_service_socket_addr,
368362
"Running deployment validation on container"
369363
);
370364

@@ -374,7 +368,7 @@ async fn run_deployment_validation(
374368
.context("Failed to create container SSH credentials")?;
375369

376370
// Create SSH connection with the container's dynamic port
377-
validate_container_deployment_with_port(&ssh_credentials, socket_addr)
371+
validate_container_deployment_with_port(&ssh_credentials, ssh_service_socket_addr)
378372
.await
379373
.context("Container deployment validation failed")?;
380374

src/e2e/containers/provisioned.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
//! let running = stopped.start().await?;
3737
//!
3838
//! // Get connection details
39-
//! let socket_addr = running.ssh_details();
39+
//! let socket_addr = running.ssh_socket_addr();
4040
//!
4141
//! // Wait for SSH server using action directly
4242
//! let ssh_wait_action = SshWaitAction::new(Duration::from_secs(30), 10);
@@ -258,9 +258,9 @@ impl RunningProvisionedContainer {
258258
}
259259
}
260260

261-
/// Get the SSH connection details for Ansible
261+
/// Get the SSH connection details
262262
#[must_use]
263-
pub fn ssh_details(&self) -> SocketAddr {
263+
pub fn ssh_socket_addr(&self) -> SocketAddr {
264264
SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), self.ssh_port)
265265
}
266266

0 commit comments

Comments
 (0)