|
| 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