Skip to content

Commit ff71179

Browse files
Copilotngocbd
andcommitted
Add comprehensive pytest integration test suite and GitHub Actions CI
Co-authored-by: ngocbd <439333+ngocbd@users.noreply.github.com>
1 parent ba3a106 commit ff71179

17 files changed

Lines changed: 2946 additions & 0 deletions
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
name: Integration Tests
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
RUST_BACKTRACE: 1
12+
13+
jobs:
14+
integration-tests:
15+
runs-on: ubuntu-latest
16+
17+
services:
18+
postgres:
19+
image: postgres:16
20+
env:
21+
POSTGRES_DB: container_engine_test
22+
POSTGRES_USER: postgres
23+
POSTGRES_PASSWORD: password
24+
options: >-
25+
--health-cmd pg_isready
26+
--health-interval 10s
27+
--health-timeout 5s
28+
--health-retries 5
29+
ports:
30+
- 5432:5432
31+
32+
redis:
33+
image: redis:7-alpine
34+
options: >-
35+
--health-cmd "redis-cli ping"
36+
--health-interval 10s
37+
--health-timeout 5s
38+
--health-retries 5
39+
ports:
40+
- 6379:6379
41+
42+
steps:
43+
- name: Checkout code
44+
uses: actions/checkout@v4
45+
46+
- name: Install Rust
47+
uses: dtolnay/rust-toolchain@stable
48+
with:
49+
components: rustfmt, clippy
50+
51+
- name: Cache Rust dependencies
52+
uses: actions/cache@v4
53+
with:
54+
path: |
55+
~/.cargo/registry
56+
~/.cargo/git
57+
target/
58+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
59+
restore-keys: |
60+
${{ runner.os }}-cargo-
61+
62+
- name: Install SQLx CLI
63+
run: cargo install sqlx-cli --no-default-features --features postgres
64+
65+
- name: Set up Python
66+
uses: actions/setup-python@v4
67+
with:
68+
python-version: '3.11'
69+
cache: 'pip'
70+
71+
- name: Install Python dependencies
72+
run: |
73+
pip install --upgrade pip
74+
pip install -r tests/requirements.txt
75+
76+
- name: Check Rust formatting
77+
run: cargo fmt --all -- --check
78+
79+
- name: Run Rust linter
80+
run: cargo clippy --all-targets --all-features -- -D warnings
81+
82+
- name: Build Rust application
83+
run: cargo build --verbose
84+
85+
- name: Set up test environment
86+
run: |
87+
# Set environment variables for the application
88+
echo "DATABASE_URL=postgresql://postgres:password@localhost:5432/container_engine_test" >> $GITHUB_ENV
89+
echo "REDIS_URL=redis://localhost:6379" >> $GITHUB_ENV
90+
echo "PORT=3000" >> $GITHUB_ENV
91+
echo "JWT_SECRET=test-jwt-secret-key-for-github-actions" >> $GITHUB_ENV
92+
echo "JWT_EXPIRES_IN=3600" >> $GITHUB_ENV
93+
echo "API_KEY_PREFIX=ce_test_" >> $GITHUB_ENV
94+
echo "KUBERNETES_NAMESPACE=test" >> $GITHUB_ENV
95+
echo "DOMAIN_SUFFIX=test.local" >> $GITHUB_ENV
96+
echo "RUST_LOG=container_engine=info,tower_http=info" >> $GITHUB_ENV
97+
98+
- name: Run database migrations
99+
run: |
100+
sqlx migrate run --database-url postgresql://postgres:password@localhost:5432/container_engine_test
101+
102+
- name: Start Container Engine server in background
103+
run: |
104+
cargo run &
105+
echo $! > server.pid
106+
107+
# Wait for server to be ready
108+
timeout 60 bash -c 'until curl -f http://localhost:3000/health; do sleep 2; done'
109+
110+
- name: Run integration tests
111+
run: |
112+
python -m pytest tests/integrate/ -v --tb=short --durations=10
113+
timeout-minutes: 15
114+
115+
- name: Stop server
116+
if: always()
117+
run: |
118+
if [ -f server.pid ]; then
119+
kill $(cat server.pid) || true
120+
rm server.pid
121+
fi
122+
123+
- name: Upload test results
124+
if: always()
125+
uses: actions/upload-artifact@v4
126+
with:
127+
name: test-results
128+
path: |
129+
pytest-report.html
130+
.pytest_cache/
131+
retention-days: 7
132+
133+
- name: Test Summary
134+
if: always()
135+
run: |
136+
echo "## Integration Test Results" >> $GITHUB_STEP_SUMMARY
137+
echo "Integration tests completed for Container Engine API" >> $GITHUB_STEP_SUMMARY
138+
if [ ${{ job.status }} == 'success' ]; then
139+
echo "✅ All tests passed!" >> $GITHUB_STEP_SUMMARY
140+
else
141+
echo "❌ Some tests failed. Check the logs above." >> $GITHUB_STEP_SUMMARY
142+
fi

pytest.ini

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
[tool:pytest]
2+
# Test discovery
3+
testpaths = tests/integrate
4+
python_files = test_*.py
5+
python_classes = Test*
6+
python_functions = test_*
7+
8+
# Markers
9+
markers =
10+
integration: marks tests as integration tests (deselect with '-m "not integration"')
11+
slow: marks tests as slow (deselect with '-m "not slow"')
12+
auth: marks tests that require authentication
13+
deployment: marks tests related to deployment functionality
14+
monitoring: marks tests related to monitoring (logs, metrics, status)
15+
domains: marks tests related to domain management
16+
17+
# Test output
18+
addopts =
19+
--strict-markers
20+
--strict-config
21+
--verbose
22+
--tb=short
23+
--durations=10
24+
-ra
25+
26+
# Timeout
27+
timeout = 300
28+
29+
# Coverage (if pytest-cov is installed)
30+
# addopts = --cov=tests --cov-report=term-missing --cov-report=html
31+
32+
# Logging
33+
log_cli = true
34+
log_cli_level = INFO
35+
log_cli_format = %(asctime)s [%(levelname)8s] %(name)s: %(message)s
36+
log_cli_date_format = %Y-%m-%d %H:%M:%S
37+
38+
# Filter warnings
39+
filterwarnings =
40+
ignore::DeprecationWarning
41+
ignore::PendingDeprecationWarning

tests/.env.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Test environment configuration for Container Engine integration tests
2+
3+
# Server settings
4+
TEST_BASE_URL=http://localhost:3000
5+
6+
# Database settings (for test isolation)
7+
TEST_DB_HOST=localhost
8+
TEST_DB_PORT=5432
9+
TEST_DB_USER=postgres
10+
TEST_DB_PASSWORD=password
11+
TEST_DB_NAME=container_engine_test
12+
13+
# Redis settings
14+
TEST_REDIS_HOST=localhost
15+
TEST_REDIS_PORT=6379
16+
17+
# Docker settings
18+
DOCKER_HOST=unix:///var/run/docker.sock

0 commit comments

Comments
 (0)