Skip to content

Commit 6e19205

Browse files
Copilotjosecelano
andcommitted
style: apply rustfmt formatting
Co-authored-by: josecelano <58816+josecelano@users.noreply.github.com>
1 parent f277803 commit 6e19205

File tree

3 files changed

+49
-20
lines changed

3 files changed

+49
-20
lines changed

src/presentation/cli/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,12 @@ mod tests {
327327

328328
#[test]
329329
fn it_should_show_create_environment_help() {
330-
let args = vec!["torrust-tracker-deployer", "create", "environment", "--help"];
330+
let args = vec![
331+
"torrust-tracker-deployer",
332+
"create",
333+
"environment",
334+
"--help",
335+
];
331336
let result = Cli::try_parse_from(args);
332337

333338
assert!(result.is_err());

src/presentation/commands/create/subcommand.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! including configuration file loading, argument processing, user interaction,
55
//! and command execution.
66
7-
use std::path::{Path, PathBuf};
7+
use std::path::Path;
88
use std::sync::Arc;
99
use std::time::Duration;
1010

@@ -40,7 +40,9 @@ pub fn handle_create_command(
4040
working_dir: &Path,
4141
) -> Result<(), CreateSubcommandError> {
4242
match action {
43-
CreateAction::Environment { env_file } => handle_environment_creation(&env_file, working_dir),
43+
CreateAction::Environment { env_file } => {
44+
handle_environment_creation(&env_file, working_dir)
45+
}
4446
CreateAction::Template { output_path } => {
4547
let template_path = output_path.unwrap_or_else(CreateAction::default_template_path);
4648
handle_template_generation(&template_path)
@@ -65,7 +67,7 @@ pub fn handle_create_command(
6567
///
6668
/// Returns an error if template file creation fails.
6769
#[allow(clippy::result_large_err)] // Error contains detailed context for user guidance
68-
fn handle_template_generation(output_path: &PathBuf) -> Result<(), CreateSubcommandError> {
70+
fn handle_template_generation(output_path: &Path) -> Result<(), CreateSubcommandError> {
6971
// Create user output for progress messages
7072
let mut output = UserOutput::new(VerbosityLevel::Normal);
7173

src/presentation/commands/create/tests/template.rs

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,23 @@ use crate::presentation::commands::create;
88
#[test]
99
fn it_should_generate_template_with_default_path() {
1010
let temp_dir = TempDir::new().unwrap();
11-
11+
1212
// Change to temp directory so template is created there
1313
let original_dir = std::env::current_dir().unwrap();
1414
std::env::set_current_dir(temp_dir.path()).unwrap();
1515

16-
let action = CreateAction::Template {
17-
output_path: None,
18-
};
16+
let action = CreateAction::Template { output_path: None };
1917

2018
let result = create::handle_create_command(action, temp_dir.path());
21-
19+
2220
// Restore original directory
2321
std::env::set_current_dir(original_dir).unwrap();
2422

25-
assert!(result.is_ok(), "Template generation should succeed: {:?}", result.err());
23+
assert!(
24+
result.is_ok(),
25+
"Template generation should succeed: {:?}",
26+
result.err()
27+
);
2628

2729
// Verify file exists at default path
2830
let template_path = temp_dir.path().join("environment-template.json");
@@ -34,8 +36,8 @@ fn it_should_generate_template_with_default_path() {
3436

3537
// Verify file content is valid JSON
3638
let content = std::fs::read_to_string(&template_path).unwrap();
37-
let parsed: serde_json::Value = serde_json::from_str(&content)
38-
.expect("Template should be valid JSON");
39+
let parsed: serde_json::Value =
40+
serde_json::from_str(&content).expect("Template should be valid JSON");
3941

4042
// Verify structure
4143
assert!(parsed["environment"]["name"].is_string());
@@ -87,12 +89,21 @@ fn it_should_generate_valid_json_template() {
8789
assert!(parsed.is_object());
8890
assert!(parsed["environment"].is_object());
8991
assert!(parsed["ssh_credentials"].is_object());
90-
92+
9193
// Verify placeholder values
92-
assert_eq!(parsed["environment"]["name"], "REPLACE_WITH_ENVIRONMENT_NAME");
93-
assert_eq!(parsed["ssh_credentials"]["private_key_path"], "REPLACE_WITH_SSH_PRIVATE_KEY_PATH");
94-
assert_eq!(parsed["ssh_credentials"]["public_key_path"], "REPLACE_WITH_SSH_PUBLIC_KEY_PATH");
95-
94+
assert_eq!(
95+
parsed["environment"]["name"],
96+
"REPLACE_WITH_ENVIRONMENT_NAME"
97+
);
98+
assert_eq!(
99+
parsed["ssh_credentials"]["private_key_path"],
100+
"REPLACE_WITH_SSH_PRIVATE_KEY_PATH"
101+
);
102+
assert_eq!(
103+
parsed["ssh_credentials"]["public_key_path"],
104+
"REPLACE_WITH_SSH_PUBLIC_KEY_PATH"
105+
);
106+
96107
// Verify default values
97108
assert_eq!(parsed["ssh_credentials"]["username"], "torrust");
98109
assert_eq!(parsed["ssh_credentials"]["port"], 22);
@@ -101,7 +112,12 @@ fn it_should_generate_valid_json_template() {
101112
#[test]
102113
fn it_should_create_parent_directories() {
103114
let temp_dir = TempDir::new().unwrap();
104-
let deep_path = temp_dir.path().join("a").join("b").join("c").join("template.json");
115+
let deep_path = temp_dir
116+
.path()
117+
.join("a")
118+
.join("b")
119+
.join("c")
120+
.join("template.json");
105121

106122
let action = CreateAction::Template {
107123
output_path: Some(deep_path.clone()),
@@ -110,6 +126,12 @@ fn it_should_create_parent_directories() {
110126
let result = create::handle_create_command(action, temp_dir.path());
111127

112128
assert!(result.is_ok(), "Should create parent directories");
113-
assert!(deep_path.exists(), "Template should be created at deep path");
114-
assert!(deep_path.parent().unwrap().exists(), "Parent directories should exist");
129+
assert!(
130+
deep_path.exists(),
131+
"Template should be created at deep path"
132+
);
133+
assert!(
134+
deep_path.parent().unwrap().exists(),
135+
"Parent directories should exist"
136+
);
115137
}

0 commit comments

Comments
 (0)