1- //! Deployment validation task for E2E testing
1+ //! Configuration validation task for E2E testing
22//!
3- //! This module provides the E2E testing task for validating that deployments
4- //! are working correctly after configuration . It performs comprehensive checks
3+ //! This module provides the E2E testing task for validating that configurations
4+ //! are working correctly after deployment . It performs comprehensive checks
55//! to ensure all required services and components are properly installed and running.
66//!
77//! ## Key Operations
@@ -29,9 +29,84 @@ use crate::infrastructure::remote_actions::{
2929 DockerComposeValidator , DockerValidator , RemoteAction ,
3030} ;
3131
32- /// Run deployment validation tests on a configured instance
32+ /// Validate Docker installation on a configured instance
3333///
34- /// This function performs comprehensive validation of a deployed instance,
34+ /// This function validates that Docker is properly installed and functioning
35+ /// on the target instance by connecting via SSH and running validation commands.
36+ ///
37+ /// # Arguments
38+ ///
39+ /// * `ip_addr` - IP address of the target instance
40+ /// * `ssh_credentials` - SSH credentials for connecting to the instance
41+ ///
42+ /// # Returns
43+ ///
44+ /// Returns `Ok(())` when Docker validation passes successfully.
45+ ///
46+ /// # Errors
47+ ///
48+ /// Returns an error if:
49+ /// - SSH connection cannot be established
50+ /// - Docker validation fails (not installed or not working)
51+ async fn validate_docker_installation (
52+ ip_addr : std:: net:: IpAddr ,
53+ ssh_credentials : & SshCredentials ,
54+ port : u16 ,
55+ ) -> Result < ( ) > {
56+ info ! ( "Validating Docker installation" ) ;
57+
58+ let ssh_connection = ssh_credentials. clone ( ) . with_host_and_port ( ip_addr, port) ;
59+
60+ let docker_validator = DockerValidator :: new ( ssh_connection) ;
61+ docker_validator
62+ . execute ( & ip_addr)
63+ . await
64+ . context ( "Docker validation failed" ) ?;
65+
66+ Ok ( ( ) )
67+ }
68+
69+ /// Validate Docker Compose installation on a configured instance
70+ ///
71+ /// This function validates that Docker Compose is properly installed and functioning
72+ /// on the target instance by connecting via SSH and running validation commands.
73+ ///
74+ /// # Arguments
75+ ///
76+ /// * `ip_addr` - IP address of the target instance
77+ /// * `ssh_credentials` - SSH credentials for connecting to the instance
78+ /// * `port` - SSH port to connect to
79+ ///
80+ /// # Returns
81+ ///
82+ /// Returns `Ok(())` when Docker Compose validation passes successfully.
83+ ///
84+ /// # Errors
85+ ///
86+ /// Returns an error if:
87+ /// - SSH connection cannot be established
88+ /// - Docker Compose validation fails (not installed or not working)
89+ async fn validate_docker_compose_installation (
90+ ip_addr : std:: net:: IpAddr ,
91+ ssh_credentials : & SshCredentials ,
92+ port : u16 ,
93+ ) -> Result < ( ) > {
94+ info ! ( "Validating Docker Compose installation" ) ;
95+
96+ let ssh_connection = ssh_credentials. clone ( ) . with_host_and_port ( ip_addr, port) ;
97+
98+ let compose_validator = DockerComposeValidator :: new ( ssh_connection) ;
99+ compose_validator
100+ . execute ( & ip_addr)
101+ . await
102+ . context ( "Docker Compose validation failed" ) ?;
103+
104+ Ok ( ( ) )
105+ }
106+
107+ /// Run configuration validation tests on a configured instance
108+ ///
109+ /// This function performs comprehensive validation of a configured instance,
35110/// checking that all required services and components are properly installed
36111/// and functioning. It uses SSH to connect to the target instance and run
37112/// validation commands.
@@ -56,7 +131,7 @@ use crate::infrastructure::remote_actions::{
56131/// # Example
57132///
58133/// ```rust,no_run
59- /// use torrust_tracker_deploy::e2e::tasks::run_deployment_validation::run_deployment_validation ;
134+ /// use torrust_tracker_deploy::e2e::tasks::run_configuration_validation::run_configuration_validation ;
60135/// use torrust_tracker_deploy::config::SshCredentials;
61136/// use std::net::{IpAddr, Ipv4Addr, SocketAddr};
62137///
@@ -69,48 +144,33 @@ use crate::infrastructure::remote_actions::{
69144/// "testuser".to_string()
70145/// );
71146///
72- /// run_deployment_validation (socket_addr, &ssh_credentials).await?;
73- /// println!("All deployment validations passed");
147+ /// run_configuration_validation (socket_addr, &ssh_credentials).await?;
148+ /// println!("All configuration validations passed");
74149/// Ok(())
75150/// }
76151/// ```
77- pub async fn run_deployment_validation (
152+ pub async fn run_configuration_validation (
78153 socket_addr : SocketAddr ,
79154 ssh_credentials : & SshCredentials ,
80155) -> Result < ( ) > {
81156 info ! (
82157 socket_addr = %socket_addr,
83158 ssh_user = %ssh_credentials. ssh_username,
84- "Running deployment validation tests"
159+ "Running configuration validation tests"
85160 ) ;
86161
87162 let ip_addr = socket_addr. ip ( ) ;
88163
89- // Create SSH connection with the instance's address and port
90- let ssh_connection = ssh_credentials
91- . clone ( )
92- . with_host_and_port ( ip_addr, socket_addr. port ( ) ) ;
93-
94164 // Validate Docker installation
95- info ! ( "Validating Docker installation" ) ;
96- let docker_validator = DockerValidator :: new ( ssh_connection. clone ( ) ) ;
97- docker_validator
98- . execute ( & ip_addr)
99- . await
100- . context ( "Docker validation failed" ) ?;
165+ validate_docker_installation ( ip_addr, ssh_credentials, socket_addr. port ( ) ) . await ?;
101166
102167 // Validate Docker Compose installation
103- info ! ( "Validating Docker Compose installation" ) ;
104- let compose_validator = DockerComposeValidator :: new ( ssh_connection) ;
105- compose_validator
106- . execute ( & ip_addr)
107- . await
108- . context ( "Docker Compose validation failed" ) ?;
168+ validate_docker_compose_installation ( ip_addr, ssh_credentials, socket_addr. port ( ) ) . await ?;
109169
110170 info ! (
111171 socket_addr = %socket_addr,
112172 status = "success" ,
113- "All deployment validation tests passed successfully"
173+ "All configuration validation tests passed successfully"
114174 ) ;
115175
116176 Ok ( ( ) )
0 commit comments