Skip to content

Commit 5b63a0f

Browse files
committed
refactor: update InventoryContextBuilder to accept typed parameters directly
- Change with_host() to accept AnsibleHost instead of &str - Change with_ssh_priv_key_path() to accept SshPrivateKeyFile instead of &str - Builder methods now return Self instead of Result<Self, Error> - Validation happens at type construction level (AnsibleHost::from_str, SshPrivateKeyFile::new) - Add concrete error types: InventoryContextError, InventoryTemplateError - Add #[must_use] attributes to builder methods - Update all test cases to use typed parameters - Update E2E tests and integration tests - All 90 tests passing, all linters passing
1 parent f821e38 commit 5b63a0f

File tree

3 files changed

+317
-56
lines changed

3 files changed

+317
-56
lines changed

src/bin/e2e_tests.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ use clap::Parser;
33
use serde_json::Value;
44
use std::path::{Path, PathBuf};
55
use std::process::{Command, Stdio};
6+
use std::str::FromStr;
67
use std::time::{Duration, Instant};
78
use tempfile::TempDir;
89
use tokio::time::sleep;
910

1011
// Import template system
1112
use torrust_tracker_deploy::template::file::File;
1213
use torrust_tracker_deploy::template::wrappers::ansible::inventory::{
13-
InventoryContext, InventoryTemplate,
14+
AnsibleHost, InventoryContext, InventoryTemplate, SshPrivateKeyFile,
1415
};
1516
use torrust_tracker_deploy::template::TemplateRenderer;
1617

@@ -143,9 +144,18 @@ impl TestEnvironment {
143144
let inventory_template_file = File::new("inventory.yml.tera", inventory_template_content)
144145
.context("Failed to create inventory template file")?;
145146

146-
let inventory_context =
147-
InventoryContext::new(container_ip, &self.ssh_key_path.to_string_lossy())
148-
.context("Failed to create InventoryContext")?;
147+
let inventory_context = {
148+
let host =
149+
AnsibleHost::from_str(container_ip).context("Failed to parse container IP")?;
150+
let ssh_key = SshPrivateKeyFile::new(self.ssh_key_path.to_string_lossy().as_ref())
151+
.context("Failed to parse SSH key path")?;
152+
153+
InventoryContext::builder()
154+
.with_host(host)
155+
.with_ssh_priv_key_path(ssh_key)
156+
.build()
157+
.context("Failed to create InventoryContext")?
158+
};
149159
let inventory_template =
150160
InventoryTemplate::new(&inventory_template_file, &inventory_context)
151161
.context("Failed to create InventoryTemplate")?;

0 commit comments

Comments
 (0)