Skip to content

Commit abc734c

Browse files
committed
refactor: add container test type and reorganize test structure
- Create new 't/container/' test type for Docker-based infrastructure tests - Move SSH connection tests from 't/e2e/' to 't/container/' - Move Docker fixtures from 't/e2e/fixtures/' to 't/container/fixtures/' - Update test script to support new 'container' test type - Update GitHub workflow to include container tests in CI - Update Perl version to v5.38 for consistency across files - Clean up e2e directory to only contain virtualization-based tests Test hierarchy now: unit < integration < container < e2e - unit: No external dependencies - integration: Multiple components, no infrastructure - container: Docker-based infrastructure testing (CI compatible) - e2e: Full virtualization (local development only)
1 parent 3543f41 commit abc734c

File tree

11 files changed

+46
-16
lines changed

11 files changed

+46
-16
lines changed

.github/copilot-instructions.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ Follow [perlstyle](https://perldoc.perl.org/5.42.0/perlstyle) conventions for co
1010

1111
#### Core Requirements
1212

13-
- **Always use strict and warnings**: `use strict; use warnings;` or `use v5.36;` (enables both)
14-
- **Modern Perl**: Use `use v5.40;` or higher for modern features (enables strict, warnings, and more)
13+
- **Modern Perl**: Use `use v5.38;` for modern features (enables strict, warnings, and more)
1514

1615
#### Naming Conventions
1716

@@ -144,7 +143,7 @@ Follow [perlstyle](https://perldoc.perl.org/5.42.0/perlstyle) conventions for co
144143
ALWAYS run the tests suite before committing any changes:
145144

146145
```bash
147-
./script/test unit integration
146+
./script/test unit integration container
148147
```
149148

150149
Note: E2E tests are excluded from pre-commit checks as they are slow and require virtualization. Run them manually when needed with `./script/test e2e` or `./script/test all`.

.github/workflows/testing.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,4 @@ jobs:
8383
# ./script/test e2e
8484
# or
8585
# ./script/test all
86-
./script/test unit integration
86+
./script/test unit integration container

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,17 +165,35 @@ The project includes two types of tests:
165165
Run unit tests that don't require virtualization:
166166

167167
```bash
168-
./script/test-unit
168+
./script/test unit
169169
```
170170

171171
These tests can run in CI environments and test individual components in isolation.
172172

173+
### Integration Tests
174+
175+
Run integration tests that require multiple components to work together:
176+
177+
```bash
178+
./script/test integration
179+
```
180+
181+
It does not require any special setup and can be run on any machine with the necessary dependencies installed.
182+
183+
### Container Tests
184+
185+
Run tests that require Docker:
186+
187+
```bash
188+
./script/test container
189+
```
190+
173191
### E2E Tests
174192

175193
Run end-to-end tests that require local virtualization support:
176194

177195
```bash
178-
./script/test-e2e
196+
./script/test e2e
179197
```
180198

181199
**Requirements for E2E tests:**

lib/TorrustDeploy/Infrastructure/SSH/Connection.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package TorrustDeploy::Infrastructure::SSH::Connection;
22

3-
use v5.40;
3+
use v5.38;
44
use Moo;
55
use Net::SSH2;
66
use Carp qw(croak);

script/test

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
11
#!/bin/bash
22

33
# Unified test script for running different test suites
4-
# Usage: ./script/test [e2e] [integration] [unit] [all]
4+
# Usage: ./script/test [e2e] [integration] [unit] [container] [all]
55
# Note: E2E tests require virtualization (KVM/QEMU) to be available on the host
6+
# Note: Container tests require Docker to be available on the host
67
# Examples:
78
# ./script/test all # Run all tests
89
# ./script/test unit integration # Run unit and integration tests only
10+
# ./script/test container # Run container tests only (requires Docker)
911
# ./script/test e2e # Run e2e tests only (requires virtualization)
1012

1113
set -e
1214

1315
# Default to no tests selected
1416
run_unit=false
1517
run_integration=false
18+
run_container=false
1619
run_e2e=false
1720

1821
# If no arguments provided, show usage
1922
if [ $# -eq 0 ]; then
20-
echo "Usage: $0 [e2e] [integration] [unit] [all]"
23+
echo "Usage: $0 [e2e] [integration] [unit] [container] [all]"
2124
echo ""
2225
echo "Note: E2E tests require virtualization (KVM/QEMU) to be available on the host"
26+
echo "Note: Container tests require Docker to be available on the host"
2327
echo ""
2428
echo "Examples:"
2529
echo " $0 all # Run all tests"
2630
echo " $0 unit integration # Run unit and integration tests only"
31+
echo " $0 container # Run container tests only (requires Docker)"
2732
echo " $0 e2e # Run e2e tests only (requires virtualization)"
2833
exit 1
2934
fi
@@ -34,6 +39,7 @@ for arg in "$@"; do
3439
all)
3540
run_unit=true
3641
run_integration=true
42+
run_container=true
3743
run_e2e=true
3844
break # If 'all' is specified, no need to check other args
3945
;;
@@ -43,12 +49,15 @@ for arg in "$@"; do
4349
integration)
4450
run_integration=true
4551
;;
52+
container)
53+
run_container=true
54+
;;
4655
e2e)
4756
run_e2e=true
4857
;;
4958
*)
5059
echo "Error: Unknown argument '$arg'"
51-
echo "Valid arguments are: e2e, integration, unit, all"
60+
echo "Valid arguments are: e2e, integration, unit, container, all"
5261
exit 1
5362
;;
5463
esac
@@ -65,6 +74,10 @@ if [ "$run_integration" = true ]; then
6574
test_dirs+=("t/integration/")
6675
fi
6776

77+
if [ "$run_container" = true ]; then
78+
test_dirs+=("t/container/")
79+
fi
80+
6881
if [ "$run_e2e" = true ]; then
6982
test_dirs+=("t/e2e/")
7083
fi
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env perl
22

3-
use v5.40;
3+
use v5.38;
44
use Test2::V0;
55
use File::Spec;
66
use Cwd qw(getcwd);
@@ -13,7 +13,7 @@ my $SSH_HOST = 'localhost';
1313
my $SSH_PORT = 2222;
1414
my $SSH_USER = 'testuser';
1515
my $SSH_PASS = 'testpass123';
16-
my $TEST_KEY_PATH = File::Spec->catfile(getcwd(), 't', 'e2e', 'fixtures', 'test_key');
16+
my $TEST_KEY_PATH = File::Spec->catfile(getcwd(), 't', 'container', 'fixtures', 'test_key');
1717

1818
# Skip tests if Docker is not available
1919
sub docker_available {
@@ -29,7 +29,7 @@ plan skip_all => 'Docker Compose not available' unless docker_compose_available(
2929

3030
# Test environment setup and teardown
3131
sub start_ssh_server {
32-
my $fixtures_dir = File::Spec->catdir(getcwd(), 't', 'e2e', 'fixtures');
32+
my $fixtures_dir = File::Spec->catdir(getcwd(), 't', 'container', 'fixtures');
3333

3434
# Stop any existing container
3535
system("cd '$fixtures_dir' && docker compose down >/dev/null 2>&1");
@@ -61,7 +61,7 @@ sub start_ssh_server {
6161
}
6262

6363
sub stop_ssh_server {
64-
my $fixtures_dir = File::Spec->catdir(getcwd(), 't', 'e2e', 'fixtures');
64+
my $fixtures_dir = File::Spec->catdir(getcwd(), 't', 'container', 'fixtures');
6565
system("cd '$fixtures_dir' && docker compose down >/dev/null 2>&1");
6666
}
6767

@@ -71,7 +71,7 @@ start_ssh_server();
7171
# Ensure cleanup happens even if tests fail
7272
END { stop_ssh_server(); }
7373

74-
subtest 'E2E SSH Connection Tests' => sub {
74+
subtest 'Container SSH Connection Tests' => sub {
7575
subtest 'Connection and Authentication' => sub {
7676
my $ssh = TorrustDeploy::Infrastructure::SSH::Connection->new(
7777
host => "$SSH_HOST:$SSH_PORT",

0 commit comments

Comments
 (0)