-
-
Notifications
You must be signed in to change notification settings - Fork 0
Testing Guide
- Overview
- Test Architecture
-
Best Approach (Implemented in
run-all-tests.sh) - Running All Tests
- Prerequisites
- Test Execution Details
- Troubleshooting
- Why Not Other Approaches?
- Success Metrics
- Integration with CI/CD
- Summary
This document explains the best practices for running the 555+ tests in the devstack-core repository.
-
Bash Integration Tests (26+ suites, 174+ tests)
- Infrastructure, databases, cache, messaging, applications
- Security: AppRole authentication (21 tests), TLS connections (24 tests)
- Performance: Redis cluster failover (16 tests)
- Run directly on host using bash scripts
-
Python Unit Tests (pytest, 254 tests: 178 passed + 76 skipped)
- FastAPI application unit tests
- Run inside Docker container
- 84.39% code coverage (exceeds 80% target)
-
Python Parity Tests (pytest, 64 tests from 38 unique test functions)
- API implementation comparison tests
- Run from host with uv
- Some tests parametrized to run against both APIs
Method: Direct execution on host
./tests/test-vault.sh
./tests/test-postgres.sh
# ... etcWhy: These tests interact with Docker containers from outside, testing real service integration.
Method: Execute inside Docker container
docker exec dev-reference-api pytest tests/ -vWhy this is the BEST approach:
- ✅ Correct Python version (3.11) - avoids Python 3.14 compatibility issues
- ✅ All dependencies pre-installed - no local environment setup needed
- ✅ Production-like environment - tests run in same env as production code
- ✅ No native extension build issues - asyncpg, etc. already compiled
- ✅ Consistent across developers - everyone uses same container image
Alternatives rejected:
- ❌ Local Python 3.14: asyncpg build fails with C compilation errors
- ❌ Local venv: Requires manual dependency management, version conflicts
Method: Run from host using uv
cd reference-apps/shared/test-suite
uv venv && uv pip install -r requirements.txt && uv run pytest -vWhy this is the BEST approach:
- ✅ Must access both APIs via localhost - localhost:8000 and localhost:8001
- ✅ Client perspective testing - tests as external client would use APIs
- ✅ Lightweight dependencies - only httpx, pytest (no heavy native extensions)
- ✅ uv handles environment - automatic venv creation and dependency management
Alternatives rejected:
- ❌ Inside container: Would need container networking, can't access localhost ports
- ❌ Local Python 3.14 directly: Works but uv provides better isolation
# Auto-starts required containers and runs all 555+ tests
./tests/run-all-tests.shThe script:
- Checks if containers are running
- Auto-starts them if needed (
docker compose up -d) - Runs bash tests (113 tests)
- Runs pytest in container (254 tests: 178 passed + 76 skipped)
- Runs parity tests with uv (64 tests)
- Shows comprehensive summary
# Pre-start containers
docker compose up -d reference-api api-first
# Run tests
./tests/run-all-tests.sh-
Docker + Docker Compose (for all services)
docker --version docker compose version
-
uv (Python package manager)
# Install curl -LsSf https://astral.sh/uv/install.sh | sh # or brew install uv # Verify uv --version
-
bash (>= 3.2)
-
dev-reference-api- FastAPI code-first implementation -
dev-api-first- FastAPI API-first implementation - All infrastructure containers (vault, postgres, redis, etc.)
# The script runs this command:
docker exec dev-reference-api pytest tests/ -v --tb=short
# Output:
# ================= 178 passed, 76 skipped, 6 warnings in 1.28s ==================
# Coverage: 84.39% (exceeds 80% requirement)What runs:
- Service unit tests (vault, cache, database)
- Router unit tests (health, vault, cache, database, messaging, redis)
- Exception handler tests
- Request validator tests
- Middleware tests (caching, circuit breaker, rate limiting)
- CORS tests
# The script runs this:
cd reference-apps/shared/test-suite
uv venv --quiet
uv pip install -r requirements.txt
uv run pytest -v
# Output:
# ============================== 26 passed in 0.35s ===============================What runs:
- Root endpoint parity
- OpenAPI spec matching
- Vault endpoint parity
- Cache endpoint parity
- Metrics format matching
- Error handling parity
- Health check parity
# Error: "dev-reference-api container not running"
# Solution: Script auto-starts it, or manually:
docker compose up -d reference-api# Error: "uv not found - required for parity tests"
# Solution:
curl -LsSf https://astral.sh/uv/install.sh | sh
# or
brew install uv# Check service health first
./devstack.sh health
# Check specific container logs
docker logs dev-reference-api
# Restart infrastructure
./devstack.sh restart- Parity tests need to access localhost:8000 and localhost:8001
- Running from inside container would require complex networking setup
- Client-perspective testing requires external access
- Python 3.14 has compatibility issues with asyncpg (C extension build failures)
- Would require matching exact Python version (3.11) locally
- Defeats purpose of containerization
- Inconsistent across developer environments
- uv is faster and handles dependency resolution better
- uv creates isolated environments automatically
- uv is the modern standard for Python package management
- No manual venv creation/activation needed
All tests passing produces this output:
Test Suites Run: 12
Passed: 12
Results by suite:
✓ Vault Integration
✓ PostgreSQL Vault Integration
✓ MySQL Vault Integration
✓ MongoDB Vault Integration
✓ Redis Vault Integration
✓ Redis Cluster
✓ RabbitMQ Integration
✓ FastAPI Reference App
✓ Performance & Load Testing
✓ Negative Testing & Error Handling
✓ FastAPI Unit Tests (pytest)
✓ API Parity Tests (pytest)
✓ ALL TESTS PASSED!
The same approach works in CI/CD:
# GitHub Actions example
- name: Run all tests
run: |
docker compose up -d reference-api api-first
./tests/run-all-tests.shBest approach is a hybrid:
- Bash tests: Direct host execution ✓
- Unit tests: Inside Docker containers ✓
- Parity tests: From host with uv ✓
This provides:
- Maximum compatibility (no Python version issues)
- Minimum setup (auto-starts containers, uv manages deps)
- Maximum reliability (production-like environment)
- Maximum clarity (each test type uses optimal approach)