Skip to content

Commit d191999

Browse files
committed
refactor: remove Infrastructure directory and restructure SSH package
- Move SSH modules from TorrustDeploy::Infrastructure::SSH::* to TorrustDeploy::SSH::* - Simplify package hierarchy by removing unnecessary Infrastructure layer - Update all internal references and imports between SSH modules - Restructure test files to match new package organization - Update test imports and fix Test::Exception dependency issues - All tests passing with cleaner, more direct package structure
1 parent 51eea19 commit d191999

File tree

7 files changed

+89
-82
lines changed

7 files changed

+89
-82
lines changed

lib/TorrustDeploy/Infrastructure/SSH/Channel.pm renamed to lib/TorrustDeploy/SSH/Channel.pm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package TorrustDeploy::Infrastructure::SSH::Channel;
1+
package TorrustDeploy::SSH::Channel;
22

33
use v5.38;
44
use Moo;
5-
use TorrustDeploy::Infrastructure::SSH::CommandResult;
5+
use TorrustDeploy::SSH::CommandResult;
66
use Carp qw(croak);
77
use namespace::clean;
88

@@ -27,7 +27,7 @@ sub execute_command {
2727
my $output = $self->read_output();
2828
my $exit_code = $self->get_exit_code();
2929

30-
return TorrustDeploy::Infrastructure::SSH::CommandResult->new(
30+
return TorrustDeploy::SSH::CommandResult->new(
3131
output => $output,
3232
exit_code => $exit_code,
3333
);
@@ -154,7 +154,7 @@ __END__
154154
155155
=head1 NAME
156156
157-
TorrustDeploy::Infrastructure::SSH::Channel - SSH channel wrapper for command execution
157+
TorrustDeploy::SSH::Channel - SSH channel wrapper for command execution
158158
159159
=head1 DESCRIPTION
160160
@@ -164,11 +164,11 @@ channel operations in a testable, reusable component.
164164
165165
=head1 SYNOPSIS
166166
167-
use TorrustDeploy::Infrastructure::SSH::Channel;
167+
use TorrustDeploy::SSH::Channel;
168168
169169
# Create channel from SSH2 connection
170170
my $raw_channel = $ssh2->channel();
171-
my $channel = TorrustDeploy::Infrastructure::SSH::Channel->new(
171+
my $channel = TorrustDeploy::SSH::Channel->new(
172172
channel => $raw_channel,
173173
timeout => 30,
174174
);

lib/TorrustDeploy/Infrastructure/SSH/CommandResult.pm renamed to lib/TorrustDeploy/SSH/CommandResult.pm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package TorrustDeploy::Infrastructure::SSH::CommandResult;
1+
package TorrustDeploy::SSH::CommandResult;
22

33
use v5.38;
44
use Moo;
@@ -66,7 +66,7 @@ __END__
6666
6767
=head1 NAME
6868
69-
TorrustDeploy::Infrastructure::SSH::CommandResult - Value object for SSH command execution results
69+
TorrustDeploy::SSH::CommandResult - Value object for SSH command execution results
7070
7171
=head1 DESCRIPTION
7272
@@ -75,15 +75,15 @@ interface and eliminating duplication of result handling logic.
7575
7676
=head1 SYNOPSIS
7777
78-
use TorrustDeploy::Infrastructure::SSH::CommandResult;
78+
use TorrustDeploy::SSH::CommandResult;
7979
8080
# Create successful result
81-
my $result = TorrustDeploy::Infrastructure::SSH::CommandResult->success_result(
81+
my $result = TorrustDeploy::SSH::CommandResult->success_result(
8282
"Command output", 0
8383
);
8484
8585
# Create failure result
86-
my $error = TorrustDeploy::Infrastructure::SSH::CommandResult->failure_result(
86+
my $error = TorrustDeploy::SSH::CommandResult->failure_result(
8787
"Command failed", 1
8888
);
8989

lib/TorrustDeploy/Infrastructure/SSH/Connection.pm renamed to lib/TorrustDeploy/SSH/Connection.pm

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package TorrustDeploy::Infrastructure::SSH::Connection;
1+
package TorrustDeploy::SSH::Connection;
22

33
use v5.38;
44
use Moo;
55
use Net::SSH2;
6-
use TorrustDeploy::Infrastructure::SSH::Channel;
7-
use TorrustDeploy::Infrastructure::SSH::CommandResult;
6+
use TorrustDeploy::SSH::Channel;
7+
use TorrustDeploy::SSH::CommandResult;
88
use Carp qw(croak);
99
use namespace::clean;
1010

@@ -172,7 +172,7 @@ sub _execute_health_check_command {
172172
return 0 unless $raw_channel;
173173

174174
# Wrap in our Channel wrapper with shorter timeout for health checks
175-
my $channel = TorrustDeploy::Infrastructure::SSH::Channel->new(
175+
my $channel = TorrustDeploy::SSH::Channel->new(
176176
channel => $raw_channel,
177177
timeout => 5, # 5 second timeout for health checks
178178
);
@@ -292,7 +292,7 @@ sub _execute_single_command {
292292
my $raw_channel = $self->_create_raw_ssh_channel($ssh2);
293293

294294
# Wrap the raw channel in our Channel wrapper
295-
my $channel = TorrustDeploy::Infrastructure::SSH::Channel->new(
295+
my $channel = TorrustDeploy::SSH::Channel->new(
296296
channel => $raw_channel,
297297
timeout => $self->command_timeout,
298298
);
@@ -338,7 +338,7 @@ sub _create_failure_result {
338338
my ($self, $error_message) = @_;
339339

340340
# Return CommandResult object directly
341-
return TorrustDeploy::Infrastructure::SSH::CommandResult->failure_result($error_message);
341+
return TorrustDeploy::SSH::CommandResult->failure_result($error_message);
342342
}
343343

344344
#==============================================================================
@@ -442,7 +442,7 @@ __END__
442442
443443
=head1 NAME
444444
445-
TorrustDeploy::Infrastructure::SSH::Connection - SSH connection management using Net::SSH2
445+
TorrustDeploy::SSH::Connection - SSH connection management using Net::SSH2
446446
447447
=head1 DESCRIPTION
448448

t/container/infrastructure/ssh/connection.t renamed to t/container/ssh/connection.t

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use File::Spec;
66
use Cwd qw(getcwd);
77

88
use lib 'lib';
9-
use TorrustDeploy::Infrastructure::SSH::Connection;
9+
use TorrustDeploy::SSH::Connection;
1010

1111
# Configuration for test SSH server
1212
my $SSH_HOST = 'localhost';
@@ -73,7 +73,7 @@ END { stop_ssh_server(); }
7373

7474
subtest 'Container SSH Connection Tests' => sub {
7575
subtest 'Connection and Authentication' => sub {
76-
my $ssh = TorrustDeploy::Infrastructure::SSH::Connection->new(
76+
my $ssh = TorrustDeploy::SSH::Connection->new(
7777
host => "$SSH_HOST:$SSH_PORT",
7878
username => $SSH_USER,
7979
password => $SSH_PASS,
@@ -93,7 +93,7 @@ subtest 'Container SSH Connection Tests' => sub {
9393
};
9494

9595
subtest 'Command Execution' => sub {
96-
my $ssh = TorrustDeploy::Infrastructure::SSH::Connection->new(
96+
my $ssh = TorrustDeploy::SSH::Connection->new(
9797
host => "$SSH_HOST:$SSH_PORT",
9898
username => $SSH_USER,
9999
password => $SSH_PASS,
@@ -124,7 +124,7 @@ subtest 'Container SSH Connection Tests' => sub {
124124
};
125125

126126
subtest 'Connection Reuse' => sub {
127-
my $ssh = TorrustDeploy::Infrastructure::SSH::Connection->new(
127+
my $ssh = TorrustDeploy::SSH::Connection->new(
128128
host => "$SSH_HOST:$SSH_PORT",
129129
username => $SSH_USER,
130130
password => $SSH_PASS,
@@ -148,7 +148,7 @@ subtest 'Container SSH Connection Tests' => sub {
148148

149149
subtest 'Authentication Fallback' => sub {
150150
# Test with wrong password but correct key
151-
my $ssh = TorrustDeploy::Infrastructure::SSH::Connection->new(
151+
my $ssh = TorrustDeploy::SSH::Connection->new(
152152
host => "$SSH_HOST:$SSH_PORT",
153153
username => $SSH_USER,
154154
password => 'wrong_password',
@@ -170,7 +170,7 @@ subtest 'Container SSH Connection Tests' => sub {
170170

171171
subtest 'Error Handling' => sub {
172172
# Test with completely wrong host
173-
my $ssh_bad_host = TorrustDeploy::Infrastructure::SSH::Connection->new(
173+
my $ssh_bad_host = TorrustDeploy::SSH::Connection->new(
174174
host => 'nonexistent.example.com:22',
175175
username => $SSH_USER,
176176
password => $SSH_PASS,
@@ -187,7 +187,7 @@ subtest 'Container SSH Connection Tests' => sub {
187187
};
188188

189189
subtest 'Disconnect and Cleanup' => sub {
190-
my $ssh = TorrustDeploy::Infrastructure::SSH::Connection->new(
190+
my $ssh = TorrustDeploy::SSH::Connection->new(
191191
host => "$SSH_HOST:$SSH_PORT",
192192
username => $SSH_USER,
193193
password => $SSH_PASS,

t/unit/infrastructure/ssh/channel.t renamed to t/unit/ssh/channel.t

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use v5.38;
44
use Test2::V0;
55

66
use lib 'lib';
7-
use TorrustDeploy::Infrastructure::SSH::Channel;
7+
use TorrustDeploy::SSH::Channel;
88

99
# Mock channel object for testing (simple hash-based mock)
1010
package MockChannel {
@@ -43,7 +43,7 @@ package MockChannel {
4343
subtest 'Constructor and Attributes' => sub {
4444
subtest 'Required attributes' => sub {
4545
my $result = dies {
46-
TorrustDeploy::Infrastructure::SSH::Channel->new()
46+
TorrustDeploy::SSH::Channel->new()
4747
};
4848
ok $result, 'dies without required channel';
4949

@@ -52,7 +52,7 @@ subtest 'Constructor and Attributes' => sub {
5252

5353
subtest 'Default values' => sub {
5454
my $mock_channel = MockChannel->new();
55-
my $channel = TorrustDeploy::Infrastructure::SSH::Channel->new(
55+
my $channel = TorrustDeploy::SSH::Channel->new(
5656
channel => $mock_channel
5757
);
5858

@@ -62,7 +62,7 @@ subtest 'Constructor and Attributes' => sub {
6262

6363
subtest 'Custom values' => sub {
6464
my $mock_channel = MockChannel->new();
65-
my $channel = TorrustDeploy::Infrastructure::SSH::Channel->new(
65+
my $channel = TorrustDeploy::SSH::Channel->new(
6666
channel => $mock_channel,
6767
timeout => 60,
6868
);
@@ -73,7 +73,7 @@ subtest 'Constructor and Attributes' => sub {
7373

7474
subtest 'Read-only attributes' => sub {
7575
my $mock_channel = MockChannel->new();
76-
my $channel = TorrustDeploy::Infrastructure::SSH::Channel->new(
76+
my $channel = TorrustDeploy::SSH::Channel->new(
7777
channel => $mock_channel
7878
);
7979

@@ -87,7 +87,7 @@ subtest 'Constructor and Attributes' => sub {
8787

8888
subtest 'Method existence' => sub {
8989
my $mock_channel = MockChannel->new();
90-
my $channel = TorrustDeploy::Infrastructure::SSH::Channel->new(
90+
my $channel = TorrustDeploy::SSH::Channel->new(
9191
channel => $mock_channel
9292
);
9393

@@ -101,7 +101,7 @@ subtest 'Method existence' => sub {
101101
subtest 'Command execution structure' => sub {
102102
my $mock_channel = MockChannel->new(exec_result => 0); # Simulate exec failure
103103

104-
my $channel = TorrustDeploy::Infrastructure::SSH::Channel->new(
104+
my $channel = TorrustDeploy::SSH::Channel->new(
105105
channel => $mock_channel
106106
);
107107

@@ -121,14 +121,14 @@ subtest 'Successful command execution' => sub {
121121
exit_status => 0,
122122
);
123123

124-
my $channel = TorrustDeploy::Infrastructure::SSH::Channel->new(
124+
my $channel = TorrustDeploy::SSH::Channel->new(
125125
channel => $mock_channel
126126
);
127127

128128
my $result = $channel->execute_command('echo test');
129129

130130
# Should return a CommandResult object
131-
is ref($result), 'TorrustDeploy::Infrastructure::SSH::CommandResult', 'execute_command returns CommandResult';
131+
is ref($result), 'TorrustDeploy::SSH::CommandResult', 'execute_command returns CommandResult';
132132

133133
# Should indicate success
134134
ok $result->is_success, 'successful command shows success = true';
@@ -143,14 +143,14 @@ subtest 'Failed command execution' => sub {
143143
exit_status => 1, # Non-zero exit
144144
);
145145

146-
my $channel = TorrustDeploy::Infrastructure::SSH::Channel->new(
146+
my $channel = TorrustDeploy::SSH::Channel->new(
147147
channel => $mock_channel
148148
);
149149

150150
my $result = $channel->execute_command('exit 1');
151151

152152
# Should return a CommandResult object
153-
is ref($result), 'TorrustDeploy::Infrastructure::SSH::CommandResult', 'execute_command returns CommandResult';
153+
is ref($result), 'TorrustDeploy::SSH::CommandResult', 'execute_command returns CommandResult';
154154

155155
# Should indicate failure
156156
ok $result->is_failure, 'failed command shows failure = true';
@@ -164,7 +164,7 @@ subtest 'Health check' => sub {
164164
read_output => 'health_check',
165165
);
166166

167-
my $channel = TorrustDeploy::Infrastructure::SSH::Channel->new(
167+
my $channel = TorrustDeploy::SSH::Channel->new(
168168
channel => $mock_channel
169169
);
170170

@@ -175,7 +175,7 @@ subtest 'Health check' => sub {
175175
subtest 'Failed health check - exec fails' => sub {
176176
my $mock_channel = MockChannel->new(exec_result => 0); # Exec fails
177177

178-
my $channel = TorrustDeploy::Infrastructure::SSH::Channel->new(
178+
my $channel = TorrustDeploy::SSH::Channel->new(
179179
channel => $mock_channel
180180
);
181181

@@ -187,7 +187,7 @@ subtest 'Health check' => sub {
187187
subtest 'Close method' => sub {
188188
my $mock_channel = MockChannel->new();
189189

190-
my $channel = TorrustDeploy::Infrastructure::SSH::Channel->new(
190+
my $channel = TorrustDeploy::SSH::Channel->new(
191191
channel => $mock_channel
192192
);
193193

0 commit comments

Comments
 (0)