Skip to content

Commit e1855e1

Browse files
committed
feat: enhance E2E tests to cover full deployment pipeline
- Remove individual test selection, now runs all playbooks in sequence - Test complete production deployment order: 1. VM provisioning with cloud-init 2. Wait for cloud-init completion (wait-cloud-init.yml) 3. Docker installation (install-docker.yml) 4. Docker Compose installation (install-docker-compose.yml) - Add validation methods for Docker and Docker Compose installations - Simplify CLI interface: just run 'cargo run --bin e2e-tests' - Update contributing documentation with new E2E usage - Add comprehensive E2E testing guide (docs/e2e-testing.md) - Fix Docker Compose test configuration for modern versions
1 parent 498b9f1 commit e1855e1

File tree

4 files changed

+348
-17
lines changed

4 files changed

+348
-17
lines changed

docs/contributing/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ cargo run --bin linter all
3737
3838
# 4. Run tests
3939
cargo test
40-
cargo run --bin e2e-tests wait-cloud-init
40+
cargo run --bin e2e-tests
4141
4242
# 5. Commit with conventional format (include issue number)
4343
git add .
@@ -50,6 +50,7 @@ git push origin 42-add-your-feature-name
5050
## 📖 Additional Resources
5151
5252
- [Main Documentation](../documentation.md) - Project documentation organization
53+
- [E2E Testing Guide](../e2e-testing.md) - End-to-end testing setup and usage
5354
- [Linting Guide](../linting.md) - Detailed linting setup and usage
5455
- [Tech Stack](../tech-stack/) - Technology-specific documentation
5556
- [Architecture Decisions](../decisions/) - Decision records and rationale

docs/contributing/commit-process.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ cargo run --bin linter shellcheck # Shell scripts
103103
cargo test
104104

105105
# Run E2E tests (if applicable to your changes)
106-
cargo run --bin e2e-tests wait-cloud-init
106+
cargo run --bin e2e-tests
107107
```
108108

109109
## 📋 Commit Quality Guidelines

docs/e2e-testing.md

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
# E2E Testing Guide
2+
3+
This guide explains how to run and understand the End-to-End (E2E) tests for the Torrust Tracker Deploy project.
4+
5+
## 🧪 What are E2E Tests?
6+
7+
The E2E tests validate the complete deployment process by:
8+
9+
1. **Provisioning infrastructure** using OpenTofu to create an LXD container
10+
2. **Running Ansible playbooks** in the correct production order
11+
3. **Validating each step** to ensure proper installation and configuration
12+
13+
## 🚀 Running E2E Tests
14+
15+
To run the full E2E test suite:
16+
17+
```bash
18+
cargo run --bin e2e-tests
19+
```
20+
21+
### Command Line Options
22+
23+
- `--keep` - Keep the test environment after completion (useful for debugging)
24+
- `--verbose` - Enable verbose output to see detailed execution steps
25+
- `--help` - Show help information
26+
27+
### Examples
28+
29+
```bash
30+
# Run with verbose output
31+
cargo run --bin e2e-tests -- --verbose
32+
33+
# Keep environment for debugging
34+
cargo run --bin e2e-tests -- --keep
35+
36+
# Combine options
37+
cargo run --bin e2e-tests -- --verbose --keep
38+
```
39+
40+
## 📋 Test Sequence
41+
42+
The E2E tests execute the following steps in production order:
43+
44+
1. **Infrastructure Provisioning**
45+
46+
- Uses OpenTofu configuration from `config/tofu/lxd/`
47+
- Creates LXD container with Ubuntu and cloud-init configuration
48+
49+
2. **Cloud-init Completion** (`wait-cloud-init.yml`)
50+
51+
- Waits for cloud-init to finish system initialization
52+
- Validates user accounts and SSH key setup
53+
54+
3. **Docker Installation** (`install-docker.yml`)
55+
56+
- Installs Docker Community Edition
57+
- Configures Docker service
58+
- Validates Docker daemon is running
59+
60+
4. **Docker Compose Installation** (`install-docker-compose.yml`)
61+
- Installs Docker Compose binary
62+
- Validates installation with test configuration
63+
64+
## 🔍 What Gets Validated
65+
66+
Each step includes validation to ensure proper setup:
67+
68+
### Cloud-init Validation
69+
70+
- ✅ Cloud-init status is "done"
71+
- ✅ Boot completion marker file exists (`/var/lib/cloud/instance/boot-finished`)
72+
73+
### Docker Validation
74+
75+
- ✅ Docker version command works
76+
- ✅ Docker daemon service is active
77+
78+
### Docker Compose Validation
79+
80+
- ✅ Docker Compose version command works
81+
- ✅ Can parse and validate a test docker-compose.yml file
82+
83+
## 🛠️ Prerequisites
84+
85+
Before running E2E tests, ensure you have:
86+
87+
1. **LXD installed and configured**
88+
89+
```bash
90+
sudo snap install lxd
91+
sudo lxd init # Follow the setup prompts
92+
```
93+
94+
2. **OpenTofu installed**
95+
96+
```bash
97+
# Installation instructions in docs/tech-stack/opentofu.md
98+
```
99+
100+
3. **Ansible installed**
101+
102+
```bash
103+
# Installation instructions in docs/tech-stack/ansible.md
104+
```
105+
106+
## 🐛 Troubleshooting
107+
108+
### Test Environment Cleanup
109+
110+
If tests fail and leave resources behind, you can manually clean up:
111+
112+
```bash
113+
# Check running containers
114+
lxc list
115+
116+
# Stop and delete the test container
117+
lxc stop torrust-vm
118+
lxc delete torrust-vm
119+
120+
# Or use OpenTofu to clean up
121+
cd config/tofu/lxd
122+
tofu destroy -auto-approve
123+
```
124+
125+
### Common Issues
126+
127+
- **SSH connectivity failures**: Usually means cloud-init is still running or SSH configuration failed
128+
- **Ansible connection errors**: Check if the container IP is accessible and SSH key permissions are correct
129+
- **OpenTofu errors**: Ensure LXD is properly configured and you have sufficient privileges
130+
131+
### Debug Mode
132+
133+
Use the `--keep` flag to inspect the environment after test completion:
134+
135+
```bash
136+
cargo run --bin e2e-tests -- --keep --verbose
137+
138+
# After test completion, connect to the container:
139+
lxc exec torrust-vm -- /bin/bash
140+
```
141+
142+
## 🏗️ Architecture
143+
144+
The E2E tests use a layered approach:
145+
146+
```text
147+
┌─────────────────────────────────────┐
148+
│ E2E Tests │
149+
│ (Rust binary: e2e-tests) │
150+
└─────────────────┬───────────────────┘
151+
152+
┌─────────────────▼───────────────────┐
153+
│ OpenTofu/LXD │
154+
│ (Infrastructure Layer) │
155+
└─────────────────┬───────────────────┘
156+
157+
┌─────────────────▼───────────────────┐
158+
│ Ansible Playbooks │
159+
│ (Configuration Layer) │
160+
└─────────────────────────────────────┘
161+
```
162+
163+
This mirrors the production deployment process where:
164+
165+
1. Infrastructure is provisioned first
166+
2. Configuration management handles software installation
167+
3. Validation ensures each step completed successfully
168+
169+
## 📝 Contributing to E2E Tests
170+
171+
When adding new playbooks or infrastructure changes:
172+
173+
1. **Update the test sequence** in `run_full_deployment_test()`
174+
2. **Add validation methods** for new components
175+
3. **Update this documentation** to reflect changes
176+
4. **Test locally** before submitting PR
177+
178+
The E2E tests are designed to catch integration issues that unit tests cannot, ensuring the entire deployment pipeline works correctly.

0 commit comments

Comments
 (0)