Skip to content

Commit 879193e

Browse files
committed
refactor: use SshConnection in validation step constructors
Replace separate SshCredentials and IpAddr parameters with a single SshConnection parameter in: - ValidateCloudInitCompletionStep::new - ValidateDockerInstallationStep::new - ValidateDockerComposeInstallationStep::new This improves encapsulation and follows the existing pattern used throughout the codebase. Updated usage in e2e_tests.rs and all corresponding unit tests.
1 parent 48d4855 commit 879193e

File tree

4 files changed

+46
-48
lines changed

4 files changed

+46
-48
lines changed

src/bin/e2e_tests.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,25 +280,26 @@ async fn validate_deployment(env: &TestEnvironment, instance_ip: &IpAddr) -> Res
280280
info!(stage = "validation", "Starting deployment validation");
281281

282282
// Validate cloud-init completion
283-
let validate_cloud_init_step =
284-
ValidateCloudInitCompletionStep::new(env.config.ssh_credentials.clone(), *instance_ip);
283+
let validate_cloud_init_step = ValidateCloudInitCompletionStep::new(
284+
env.config.ssh_credentials.clone().with_host(*instance_ip),
285+
);
285286
validate_cloud_init_step
286287
.execute()
287288
.await
288289
.map_err(|e| anyhow::anyhow!(e))?;
289290

290291
// Validate Docker installation
291-
let validate_docker_step =
292-
ValidateDockerInstallationStep::new(env.config.ssh_credentials.clone(), *instance_ip);
292+
let validate_docker_step = ValidateDockerInstallationStep::new(
293+
env.config.ssh_credentials.clone().with_host(*instance_ip),
294+
);
293295
validate_docker_step
294296
.execute()
295297
.await
296298
.map_err(|e| anyhow::anyhow!(e))?;
297299

298300
// Validate Docker Compose installation
299301
let validate_docker_compose_step = ValidateDockerComposeInstallationStep::new(
300-
env.config.ssh_credentials.clone(),
301-
*instance_ip,
302+
env.config.ssh_credentials.clone().with_host(*instance_ip),
302303
);
303304
validate_docker_compose_step
304305
.execute()

src/steps/infrastructure/validate_cloud_init_completion.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
1-
use std::net::IpAddr;
21
use tracing::info;
32

43
use crate::actions::{CloudInitValidator, RemoteAction, RemoteActionError};
5-
use crate::command_wrappers::ssh::SshCredentials;
4+
use crate::command_wrappers::ssh::SshConnection;
65

76
/// Step that validates cloud-init completion on a remote host
87
pub struct ValidateCloudInitCompletionStep {
9-
ssh_credentials: SshCredentials,
10-
host_ip: IpAddr,
8+
ssh_connection: SshConnection,
119
}
1210

1311
impl ValidateCloudInitCompletionStep {
1412
#[must_use]
15-
pub fn new(ssh_credentials: SshCredentials, host_ip: IpAddr) -> Self {
16-
Self {
17-
ssh_credentials,
18-
host_ip,
19-
}
13+
pub fn new(ssh_connection: SshConnection) -> Self {
14+
Self { ssh_connection }
2015
}
2116

2217
/// Execute the cloud-init completion validation step
@@ -43,10 +38,11 @@ impl ValidateCloudInitCompletionStep {
4338
"Validating cloud-init completion"
4439
);
4540

46-
let cloud_init_ssh_connection = self.ssh_credentials.clone().with_host(self.host_ip);
47-
let cloud_init_validator = CloudInitValidator::new(cloud_init_ssh_connection);
41+
let cloud_init_validator = CloudInitValidator::new(self.ssh_connection.clone());
4842

49-
cloud_init_validator.execute(&self.host_ip).await?;
43+
cloud_init_validator
44+
.execute(&self.ssh_connection.host_ip)
45+
.await?;
5046

5147
Ok(())
5248
}
@@ -57,6 +53,8 @@ mod tests {
5753
use std::net::{IpAddr, Ipv4Addr};
5854
use std::path::PathBuf;
5955

56+
use crate::command_wrappers::ssh::SshCredentials;
57+
6058
use super::*;
6159

6260
#[test]
@@ -67,10 +65,11 @@ mod tests {
6765
"test_user".to_string(),
6866
);
6967
let host_ip = IpAddr::V4(Ipv4Addr::new(192, 168, 1, 1));
68+
let ssh_connection = ssh_credentials.with_host(host_ip);
7069

71-
let step = ValidateCloudInitCompletionStep::new(ssh_credentials, host_ip);
70+
let step = ValidateCloudInitCompletionStep::new(ssh_connection);
7271

7372
// Test that the step can be created successfully
74-
assert_eq!(step.host_ip, host_ip);
73+
assert_eq!(step.ssh_connection.host_ip, host_ip);
7574
}
7675
}

src/steps/infrastructure/validate_docker_compose_installation.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
1-
use std::net::IpAddr;
21
use tracing::info;
32

43
use crate::actions::{DockerComposeValidator, RemoteAction, RemoteActionError};
5-
use crate::command_wrappers::ssh::SshCredentials;
4+
use crate::command_wrappers::ssh::SshConnection;
65

76
/// Step that validates Docker Compose installation on a remote host
87
pub struct ValidateDockerComposeInstallationStep {
9-
ssh_credentials: SshCredentials,
10-
host_ip: IpAddr,
8+
ssh_connection: SshConnection,
119
}
1210

1311
impl ValidateDockerComposeInstallationStep {
1412
#[must_use]
15-
pub fn new(ssh_credentials: SshCredentials, host_ip: IpAddr) -> Self {
16-
Self {
17-
ssh_credentials,
18-
host_ip,
19-
}
13+
pub fn new(ssh_connection: SshConnection) -> Self {
14+
Self { ssh_connection }
2015
}
2116

2217
/// Execute the Docker Compose installation validation step
@@ -43,10 +38,11 @@ impl ValidateDockerComposeInstallationStep {
4338
"Validating Docker Compose installation"
4439
);
4540

46-
let docker_compose_ssh_connection = self.ssh_credentials.clone().with_host(self.host_ip);
47-
let docker_compose_validator = DockerComposeValidator::new(docker_compose_ssh_connection);
41+
let docker_compose_validator = DockerComposeValidator::new(self.ssh_connection.clone());
4842

49-
docker_compose_validator.execute(&self.host_ip).await?;
43+
docker_compose_validator
44+
.execute(&self.ssh_connection.host_ip)
45+
.await?;
5046

5147
Ok(())
5248
}
@@ -57,6 +53,8 @@ mod tests {
5753
use std::net::{IpAddr, Ipv4Addr};
5854
use std::path::PathBuf;
5955

56+
use crate::command_wrappers::ssh::SshCredentials;
57+
6058
use super::*;
6159

6260
#[test]
@@ -67,10 +65,11 @@ mod tests {
6765
"test_user".to_string(),
6866
);
6967
let host_ip = IpAddr::V4(Ipv4Addr::new(192, 168, 1, 1));
68+
let ssh_connection = ssh_credentials.with_host(host_ip);
7069

71-
let step = ValidateDockerComposeInstallationStep::new(ssh_credentials, host_ip);
70+
let step = ValidateDockerComposeInstallationStep::new(ssh_connection);
7271

7372
// Test that the step can be created successfully
74-
assert_eq!(step.host_ip, host_ip);
73+
assert_eq!(step.ssh_connection.host_ip, host_ip);
7574
}
7675
}

src/steps/infrastructure/validate_docker_installation.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
1-
use std::net::IpAddr;
21
use tracing::info;
32

43
use crate::actions::{DockerValidator, RemoteAction, RemoteActionError};
5-
use crate::command_wrappers::ssh::SshCredentials;
4+
use crate::command_wrappers::ssh::SshConnection;
65

76
/// Step that validates Docker installation on a remote host
87
pub struct ValidateDockerInstallationStep {
9-
ssh_credentials: SshCredentials,
10-
host_ip: IpAddr,
8+
ssh_connection: SshConnection,
119
}
1210

1311
impl ValidateDockerInstallationStep {
1412
#[must_use]
15-
pub fn new(ssh_credentials: SshCredentials, host_ip: IpAddr) -> Self {
16-
Self {
17-
ssh_credentials,
18-
host_ip,
19-
}
13+
pub fn new(ssh_connection: SshConnection) -> Self {
14+
Self { ssh_connection }
2015
}
2116

2217
/// Execute the Docker installation validation step
@@ -43,10 +38,11 @@ impl ValidateDockerInstallationStep {
4338
"Validating Docker installation"
4439
);
4540

46-
let docker_ssh_connection = self.ssh_credentials.clone().with_host(self.host_ip);
47-
let docker_validator = DockerValidator::new(docker_ssh_connection);
41+
let docker_validator = DockerValidator::new(self.ssh_connection.clone());
4842

49-
docker_validator.execute(&self.host_ip).await?;
43+
docker_validator
44+
.execute(&self.ssh_connection.host_ip)
45+
.await?;
5046

5147
Ok(())
5248
}
@@ -57,6 +53,8 @@ mod tests {
5753
use std::net::{IpAddr, Ipv4Addr};
5854
use std::path::PathBuf;
5955

56+
use crate::command_wrappers::ssh::SshCredentials;
57+
6058
use super::*;
6159

6260
#[test]
@@ -67,10 +65,11 @@ mod tests {
6765
"test_user".to_string(),
6866
);
6967
let host_ip = IpAddr::V4(Ipv4Addr::new(192, 168, 1, 1));
68+
let ssh_connection = ssh_credentials.with_host(host_ip);
7069

71-
let step = ValidateDockerInstallationStep::new(ssh_credentials, host_ip);
70+
let step = ValidateDockerInstallationStep::new(ssh_connection);
7271

7372
// Test that the step can be created successfully
74-
assert_eq!(step.host_ip, host_ip);
73+
assert_eq!(step.ssh_connection.host_ip, host_ip);
7574
}
7675
}

0 commit comments

Comments
 (0)