|  | 
| 4 | 4 | 
 | 
| 5 | 5 | use std::sync::Arc; | 
| 6 | 6 | 
 | 
| 7 |  | -use chrono::{TimeZone, Utc}; | 
| 8 |  | - | 
| 9 |  | -use super::builders::{create_test_environment, ProvisionCommandHandlerTestBuilder}; | 
|  | 7 | +use super::builders::ProvisionCommandHandlerTestBuilder; | 
| 10 | 8 | use crate::adapters::ssh::SshError; | 
| 11 | 9 | use crate::adapters::tofu::client::OpenTofuError; | 
| 12 | 10 | use crate::application::command_handlers::provision::ProvisionCommandHandlerError; | 
| 13 |  | -use crate::domain::environment::state::ProvisionStep; | 
| 14 | 11 | use crate::infrastructure::external_tools::tofu::ProvisionTemplateError; | 
| 15 | 12 | use crate::shared::command::CommandError; | 
| 16 | 13 | 
 | 
| @@ -66,113 +63,3 @@ fn it_should_have_correct_error_type_conversions() { | 
| 66 | 63 |     let provision_error: ProvisionCommandHandlerError = ssh_error.into(); | 
| 67 | 64 |     drop(provision_error); | 
| 68 | 65 | } | 
| 69 |  | - | 
| 70 |  | -#[test] | 
| 71 |  | -fn it_should_build_failure_context_from_opentofu_template_error() { | 
| 72 |  | -    let (command_handler, temp_dir, _ssh_credentials) = | 
| 73 |  | -        ProvisionCommandHandlerTestBuilder::new().build(); | 
| 74 |  | - | 
| 75 |  | -    let (environment, _env_temp_dir) = create_test_environment(&temp_dir); | 
| 76 |  | - | 
| 77 |  | -    let error = ProvisionCommandHandlerError::OpenTofuTemplateRendering( | 
| 78 |  | -        ProvisionTemplateError::DirectoryCreationFailed { | 
| 79 |  | -            directory: "/test".to_string(), | 
| 80 |  | -            source: std::io::Error::new(std::io::ErrorKind::PermissionDenied, "test"), | 
| 81 |  | -        }, | 
| 82 |  | -    ); | 
| 83 |  | - | 
| 84 |  | -    let started_at = Utc.with_ymd_and_hms(2025, 10, 7, 12, 0, 0).unwrap(); | 
| 85 |  | -    let current_step = ProvisionStep::RenderOpenTofuTemplates; | 
| 86 |  | -    let context = | 
| 87 |  | -        command_handler.build_failure_context(&environment, &error, current_step, started_at); | 
| 88 |  | -    assert_eq!(context.failed_step, ProvisionStep::RenderOpenTofuTemplates); | 
| 89 |  | -    assert_eq!( | 
| 90 |  | -        context.error_kind, | 
| 91 |  | -        crate::shared::ErrorKind::TemplateRendering | 
| 92 |  | -    ); | 
| 93 |  | -    assert_eq!(context.base.execution_started_at, started_at); | 
| 94 |  | -} | 
| 95 |  | - | 
| 96 |  | -// Note: We don't test AnsibleTemplateRendering errors directly as the error types are complex | 
| 97 |  | -// and deeply nested. The build_failure_context method handles them by matching on the | 
| 98 |  | -// ProvisionCommandHandlerError::AnsibleTemplateRendering variant, which is sufficient for | 
| 99 |  | -// error context generation. | 
| 100 |  | - | 
| 101 |  | -#[test] | 
| 102 |  | -fn it_should_build_failure_context_from_ssh_connectivity_error() { | 
| 103 |  | -    let (command_handler, temp_dir, _ssh_credentials) = | 
| 104 |  | -        ProvisionCommandHandlerTestBuilder::new().build(); | 
| 105 |  | - | 
| 106 |  | -    let (environment, _env_temp_dir) = create_test_environment(&temp_dir); | 
| 107 |  | - | 
| 108 |  | -    let error = ProvisionCommandHandlerError::SshConnectivity(SshError::ConnectivityTimeout { | 
| 109 |  | -        host_ip: "127.0.0.1".to_string(), | 
| 110 |  | -        attempts: 5, | 
| 111 |  | -        timeout_seconds: 30, | 
| 112 |  | -    }); | 
| 113 |  | - | 
| 114 |  | -    let started_at = Utc.with_ymd_and_hms(2025, 10, 7, 12, 0, 0).unwrap(); | 
| 115 |  | -    let current_step = ProvisionStep::WaitSshConnectivity; | 
| 116 |  | -    let context = | 
| 117 |  | -        command_handler.build_failure_context(&environment, &error, current_step, started_at); | 
| 118 |  | -    assert_eq!(context.failed_step, ProvisionStep::WaitSshConnectivity); | 
| 119 |  | -    assert_eq!( | 
| 120 |  | -        context.error_kind, | 
| 121 |  | -        crate::shared::ErrorKind::NetworkConnectivity | 
| 122 |  | -    ); | 
| 123 |  | -    assert_eq!(context.base.execution_started_at, started_at); | 
| 124 |  | -} | 
| 125 |  | - | 
| 126 |  | -#[test] | 
| 127 |  | -fn it_should_build_failure_context_from_command_error() { | 
| 128 |  | -    let (command_handler, temp_dir, _ssh_credentials) = | 
| 129 |  | -        ProvisionCommandHandlerTestBuilder::new().build(); | 
| 130 |  | - | 
| 131 |  | -    let (environment, _env_temp_dir) = create_test_environment(&temp_dir); | 
| 132 |  | - | 
| 133 |  | -    let error = ProvisionCommandHandlerError::Command(CommandError::ExecutionFailed { | 
| 134 |  | -        command: "test".to_string(), | 
| 135 |  | -        exit_code: "1".to_string(), | 
| 136 |  | -        stdout: String::new(), | 
| 137 |  | -        stderr: "test error".to_string(), | 
| 138 |  | -    }); | 
| 139 |  | - | 
| 140 |  | -    let started_at = Utc.with_ymd_and_hms(2025, 10, 7, 12, 0, 0).unwrap(); | 
| 141 |  | -    let current_step = ProvisionStep::CloudInitWait; | 
| 142 |  | -    let context = | 
| 143 |  | -        command_handler.build_failure_context(&environment, &error, current_step, started_at); | 
| 144 |  | -    assert_eq!(context.failed_step, ProvisionStep::CloudInitWait); | 
| 145 |  | -    assert_eq!( | 
| 146 |  | -        context.error_kind, | 
| 147 |  | -        crate::shared::ErrorKind::CommandExecution | 
| 148 |  | -    ); | 
| 149 |  | -    assert_eq!(context.base.execution_started_at, started_at); | 
| 150 |  | -} | 
| 151 |  | - | 
| 152 |  | -#[test] | 
| 153 |  | -fn it_should_build_failure_context_from_opentofu_error() { | 
| 154 |  | -    let (command_handler, temp_dir, _ssh_credentials) = | 
| 155 |  | -        ProvisionCommandHandlerTestBuilder::new().build(); | 
| 156 |  | - | 
| 157 |  | -    let (environment, _env_temp_dir) = create_test_environment(&temp_dir); | 
| 158 |  | - | 
| 159 |  | -    let opentofu_error = OpenTofuError::CommandError(CommandError::ExecutionFailed { | 
| 160 |  | -        command: "tofu init".to_string(), | 
| 161 |  | -        exit_code: "1".to_string(), | 
| 162 |  | -        stdout: String::new(), | 
| 163 |  | -        stderr: "init failed".to_string(), | 
| 164 |  | -    }); | 
| 165 |  | - | 
| 166 |  | -    let error = ProvisionCommandHandlerError::OpenTofu(opentofu_error); | 
| 167 |  | - | 
| 168 |  | -    let started_at = Utc.with_ymd_and_hms(2025, 10, 7, 12, 0, 0).unwrap(); | 
| 169 |  | -    let current_step = ProvisionStep::OpenTofuInit; | 
| 170 |  | -    let context = | 
| 171 |  | -        command_handler.build_failure_context(&environment, &error, current_step, started_at); | 
| 172 |  | -    assert_eq!(context.failed_step, ProvisionStep::OpenTofuInit); | 
| 173 |  | -    assert_eq!( | 
| 174 |  | -        context.error_kind, | 
| 175 |  | -        crate::shared::ErrorKind::InfrastructureOperation | 
| 176 |  | -    ); | 
| 177 |  | -    assert_eq!(context.base.execution_started_at, started_at); | 
| 178 |  | -} | 
0 commit comments