Skip to content

Commit 1cdf7b4

Browse files
authored
Merge pull request #4 from ngocbd/copilot/fix-ff0b7d53-96c5-4797-bab6-a3412226fc3d
Add comprehensive pytest integration test suite and GitHub Actions CI for API endpoint validation
2 parents 4f8869a + af1e0b4 commit 1cdf7b4

22 files changed

Lines changed: 3428 additions & 4 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

.gitignore

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,55 @@ dump.rdb
3434
.dockerignore
3535

3636
# Kubernetes
37-
*.kubeconfig
37+
*.kubeconfig
38+
39+
# Python
40+
__pycache__/
41+
*.py[cod]
42+
*$py.class
43+
*.so
44+
.Python
45+
build/
46+
develop-eggs/
47+
dist/
48+
downloads/
49+
eggs/
50+
.eggs/
51+
lib/
52+
lib64/
53+
parts/
54+
sdist/
55+
var/
56+
wheels/
57+
*.egg-info/
58+
.installed.cfg
59+
*.egg
60+
MANIFEST
61+
62+
# Testing
63+
.pytest_cache/
64+
.coverage
65+
htmlcov/
66+
.tox/
67+
.nox/
68+
.coverage.*
69+
pytest-report.html
70+
.cache
71+
nosetests.xml
72+
coverage.xml
73+
*.cover
74+
.hypothesis/
75+
76+
# Virtual environments
77+
.env
78+
.venv
79+
env/
80+
venv/
81+
ENV/
82+
env.bak/
83+
venv.bak/
84+
85+
# Test artifacts
86+
tests/.env.test.local
87+
tests/test-results/
88+
tests/artifacts/

0 commit comments

Comments
 (0)