Skip to content

Commit f115545

Browse files
committed
ci: [#14] separate CI-compatible tests from virtualization-required tests
- Add test-ci and test-local targets to Makefile for clear test separation - Update GitHub Actions workflow to run make test-ci with all dependencies - Create orchestration scripts for CI (test-ci.sh) and local (test-local.sh) testing - Add unit test scripts for config, scripts, and infrastructure validation - Remove deprecated test-integration.sh and test-local-setup.sh - Document testing strategy in ci-vs-local-test-analysis.md - Update infrastructure test documentation and project references - Improve Makefile help output to clarify testing workflow This enables running syntax validation, config validation, and unit tests in GitHub Actions while keeping full E2E infrastructure tests for local development with virtualization support.
1 parent 40a669e commit f115545

18 files changed

+1826
-1035
lines changed

.github/workflows/testing.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,24 @@ on:
77
branches: [main, develop]
88

99
jobs:
10-
lint:
10+
ci-tests:
1111
runs-on: ubuntu-latest
12+
name: CI-Compatible Tests
1213

1314
steps:
1415
- name: Checkout code
1516
uses: actions/checkout@v4
1617

17-
- name: Install linting tools
18+
- name: Install dependencies
1819
run: |
1920
sudo apt-get update
20-
sudo apt-get install -y yamllint shellcheck
21+
sudo apt-get install -y yamllint shellcheck docker-compose
2122
sudo npm install -g markdownlint-cli
2223
23-
- name: Run linting script
24-
run: |
25-
./scripts/lint.sh
24+
# Install OpenTofu
25+
curl -fsSL https://get.opentofu.org/install-opentofu.sh -o install-opentofu.sh
26+
chmod +x install-opentofu.sh
27+
sudo ./install-opentofu.sh --install-method deb
28+
29+
- name: Run CI test suite
30+
run: make test-ci

Makefile

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
VM_NAME ?= torrust-tracker-demo
1010
ENVIRONMENT ?= local
1111
TERRAFORM_DIR = infrastructure/terraform
12-
TESTS_DIR = infrastructure/tests
12+
INFRA_TESTS_DIR = infrastructure/tests
13+
TESTS_DIR = tests
1314
SCRIPTS_DIR = infrastructure/scripts
1415

1516
# Help target
@@ -21,6 +22,13 @@ help: ## Show this help message
2122
@echo " 2. app-deploy - Deploy application (Build + Release + Run stages)"
2223
@echo " 3. health-check - Validate deployment"
2324
@echo ""
25+
@echo "=== TESTING WORKFLOW ==="
26+
@echo " 1. test-syntax - Fast syntax validation (30s)"
27+
@echo " 2. test-unit - Unit tests without deployment (1-2min)"
28+
@echo " 3. test-ci - CI-compatible tests (syntax + config + scripts)"
29+
@echo " 4. test-local - Local-only tests (requires virtualization)"
30+
@echo " 5. test - Full E2E test with deployment (5-8min)"
31+
@echo ""
2432
@echo "Available targets:"
2533
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-20s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
2634
@echo ""
@@ -123,14 +131,38 @@ validate-config: ## Validate configuration for all environments
123131
# TESTING AND QUALITY ASSURANCE
124132
# =============================================================================
125133

126-
test: ## Run comprehensive test suite
127-
@echo "Running comprehensive test suite..."
128-
$(TESTS_DIR)/test-local-setup.sh
134+
test-prereq: ## Test system prerequisites for development
135+
@echo "Testing prerequisites..."
136+
$(INFRA_TESTS_DIR)/test-unit-infrastructure.sh vm-prereq
137+
138+
test: ## Run comprehensive end-to-end test (follows integration guide)
139+
@echo "Running comprehensive end-to-end test..."
140+
$(TESTS_DIR)/test-e2e.sh $(ENVIRONMENT)
141+
142+
test-unit: ## Run unit tests (configuration, scripts, syntax)
143+
@echo "Running unit tests..."
144+
@echo "1. Configuration and syntax validation..."
145+
$(INFRA_TESTS_DIR)/test-unit-config.sh
146+
@echo "2. Infrastructure scripts validation..."
147+
$(INFRA_TESTS_DIR)/test-unit-scripts.sh
129148

130149
test-syntax: ## Run syntax validation only
131150
@echo "Running syntax validation..."
132151
./scripts/lint.sh
133152

153+
test-ci: ## Run CI-compatible tests (syntax + config + scripts)
154+
@echo "Running CI-compatible tests..."
155+
$(INFRA_TESTS_DIR)/test-ci.sh
156+
157+
test-local: ## Run local-only tests (requires virtualization)
158+
@echo "Running local-only tests..."
159+
$(INFRA_TESTS_DIR)/test-local.sh
160+
161+
test-legacy: ## [DEPRECATED] Legacy test scripts have been removed
162+
@echo "⚠️ DEPRECATED: Legacy test scripts have been removed"
163+
@echo "Use 'make test-unit' for unit tests or 'make test' for E2E tests"
164+
@exit 1
165+
134166
lint: test-syntax ## Run all linting (alias for test-syntax)
135167

136168
clean: ## Clean up temporary files and caches

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ It's also used to track issues in production.
1212
1313
## 🏗️ Repository Structure
1414

15-
This repository is organized into two main concerns:
15+
This repository is organized into distinct concerns:
1616

1717
### 📦 [`infrastructure/`](infrastructure/)
1818

@@ -21,7 +21,7 @@ This repository is organized into two main concerns:
2121
- OpenTofu/Terraform for VM provisioning
2222
- cloud-init templates for system setup
2323
- libvirt/KVM for local testing
24-
- Infrastructure testing and validation
24+
- Infrastructure unit tests and validation
2525

2626
### 🚀 [`application/`](application/)
2727

@@ -32,6 +32,14 @@ This repository is organized into two main concerns:
3232
- Nginx, Prometheus, Grafana setup
3333
- Application scripts and utilities
3434

35+
### 🧪 [`tests/`](tests/)
36+
37+
**End-to-end testing** - Complete system validation
38+
39+
- E2E deployment workflow tests
40+
- Integration testing automation
41+
- System-wide validation
42+
3543
### 📚 [`docs/`](docs/)
3644

3745
**Project documentation** - Guides, security, and reference materials

docs/guides/integration-testing-guide.md

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -942,8 +942,12 @@ for better compatibility with modern compose.yaml files.
942942
### 4.1 Test VM Access
943943

944944
```bash
945-
# [PROJECT_ROOT] Test basic VM connectivity
946-
time ./infrastructure/tests/test-integration.sh access
945+
# [PROJECT_ROOT] Test basic VM connectivity using SSH
946+
make ssh
947+
948+
# Or test connectivity manually
949+
VM_IP=$(cd infrastructure/terraform && tofu output -raw vm_ip)
950+
ssh torrust@$VM_IP "echo 'VM is accessible'"
947951
```
948952

949953
**Expected Output**:
@@ -955,8 +959,14 @@ time ./infrastructure/tests/test-integration.sh access
955959
### 4.2 Test Docker Installation
956960

957961
```bash
958-
# [PROJECT_ROOT] Test Docker functionality
959-
time ./infrastructure/tests/test-integration.sh docker
962+
# [PROJECT_ROOT] Test Docker functionality via health check
963+
make health-check
964+
965+
# Or test Docker manually via SSH
966+
make ssh
967+
# Then inside VM:
968+
docker --version
969+
docker compose version
960970
```
961971

962972
**Expected Output**:
@@ -973,8 +983,8 @@ available and uses the appropriate command.
973983
### 4.3 Setup Torrust Tracker Demo
974984

975985
```bash
976-
# [PROJECT_ROOT] Clone and setup the Torrust Tracker repository
977-
time ./infrastructure/tests/test-integration.sh setup
986+
# [PROJECT_ROOT] Deploy the application using twelve-factor workflow
987+
make app-deploy
978988
```
979989

980990
**Expected Output**:
@@ -989,8 +999,10 @@ configuration.
989999
### 4.4 Start Torrust Tracker Services
9901000

9911001
```bash
992-
# [PROJECT_ROOT] Pull images and start all services
993-
time ./infrastructure/tests/test-integration.sh start
1002+
# [PROJECT_ROOT] Application deployment includes starting services
1003+
# Services are automatically started by 'make app-deploy'
1004+
# To verify services are running:
1005+
make health-check
9941006
```
9951007

9961008
**Expected Output**:
@@ -1010,8 +1022,8 @@ time ./infrastructure/tests/test-integration.sh start
10101022
### 4.5 Test Service Endpoints
10111023

10121024
```bash
1013-
# [PROJECT_ROOT] Test all API endpoints
1014-
time ./infrastructure/tests/test-integration.sh endpoints
1025+
# [PROJECT_ROOT] Test all endpoints via comprehensive health check
1026+
make health-check
10151027
```
10161028

10171029
**Expected Output**:
@@ -1028,8 +1040,11 @@ requirements. For manual testing, see Step 5.2 for the correct endpoint testing
10281040
### 4.6 Test Monitoring Services
10291041

10301042
```bash
1031-
# [PROJECT_ROOT] Test Prometheus and Grafana
1032-
time ./infrastructure/tests/test-integration.sh monitoring
1043+
# [PROJECT_ROOT] Test Prometheus and Grafana via health check
1044+
make health-check
1045+
1046+
# For detailed monitoring, connect via SSH to inspect services directly
1047+
make ssh
10331048
```
10341049

10351050
**Expected Output**:
@@ -1041,8 +1056,8 @@ time ./infrastructure/tests/test-integration.sh monitoring
10411056
### 4.7 Run Complete Integration Test Suite
10421057

10431058
```bash
1044-
# [PROJECT_ROOT] Run all tests in sequence
1045-
time ./infrastructure/tests/test-integration.sh full-test
1059+
# [PROJECT_ROOT] Run complete E2E test (infrastructure + application + health)
1060+
make test
10461061
```
10471062

10481063
**Expected Output**:
@@ -1541,8 +1556,11 @@ time (cd "$TRACKER_DIR" && cargo run -p torrust-tracker-client --bin http_tracke
15411556
### 8.1 Stop Services (if needed)
15421557

15431558
```bash
1544-
# [PROJECT_ROOT] Stop all services cleanly
1545-
./infrastructure/tests/test-integration.sh stop
1559+
# [PROJECT_ROOT] Stop services via SSH if needed
1560+
make ssh
1561+
# Then inside VM:
1562+
cd /home/torrust/github/torrust/torrust-tracker-demo/application
1563+
docker compose down
15461564
```
15471565

15481566
### 8.2 Destroy VM and Clean Up
@@ -1669,17 +1687,17 @@ curl http://$VM_IP/api/v1/stats
16691687
curl "http://$VM_IP/api/v1/stats?token=local-dev-admin-token-12345"
16701688
```
16711689

1672-
### 9.4 Integration Test Script Limitations
1690+
### 9.4 Health Check Limitations
16731691

1674-
The automated integration test script (`./infrastructure/tests/test-integration.sh endpoints`)
1675-
may fail because:
1692+
The automated health check script (`make health-check`) provides comprehensive
1693+
validation but may need tuning for specific scenarios:
16761694

1677-
1. **Authentication**: Script doesn't include token for stats API
1678-
2. **Port Assumptions**: May test internal ports instead of nginx proxy
1679-
3. **JSON Parsing**: Doesn't use `jq` for response validation
1695+
1. **Timeouts**: Some tests use conservative timeouts that may be slow
1696+
2. **Test Coverage**: Focuses on connectivity rather than functional testing
1697+
3. **Verbose Output**: Use `VERBOSE=true make health-check` for detailed results
16801698

1681-
**Manual testing** (as shown in this guide) provides more reliable results and
1682-
better insight into the actual API functionality.
1699+
**Manual testing** (as shown in this guide) provides more detailed functional
1700+
validation and better insight into the actual API behavior.
16831701

16841702
### 9.5 Useful Testing Commands
16851703

@@ -1798,7 +1816,7 @@ ls -la | grep -E "(Makefile|infrastructure|application)"
17981816

17991817
- `make: *** No rule to make target 'configure-local'. Stop.`
18001818
- `make: *** No such file or directory. Stop.`
1801-
- `./infrastructure/tests/test-integration.sh: No such file or directory`
1819+
- Commands like `make infra-apply` failing with file not found errors
18021820

18031821
**Solution**: Always ensure you're in the project root directory before running commands.
18041822

0 commit comments

Comments
 (0)