Skip to content

Commit ba8f287

Browse files
committed
feat: 新增pg测试
1 parent 37a54f2 commit ba8f287

File tree

6 files changed

+283
-119
lines changed

6 files changed

+283
-119
lines changed

.github/workflows/playwright.yml

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
name: Playwright Tests
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
mysql-test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
python-version: ["3.9", "3.10", "3.11", "3.12"]
16+
17+
steps:
18+
- uses: actions/checkout@v5
19+
20+
- name: Set up Python ${{ matrix.python-version }}
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: ${{ matrix.python-version }}
24+
25+
- name: Cache Docker layers
26+
uses: actions/cache@v5
27+
with:
28+
path: /tmp/.docker_cache
29+
key: ${{ runner.os }}-docker-${{ matrix.python-version }}-${{ hashFiles('**/Dockerfile*', '**/requirements.txt') }}
30+
31+
- name: Set up Docker Buildx
32+
uses: docker/setup-buildx-action@v3
33+
34+
- name: Create temporary Dockerfile with Python ${{ matrix.python-version }}
35+
run: |
36+
# Save original Dockerfile.my
37+
cp ruoyi-fastapi-backend/Dockerfile.my ruoyi-fastapi-backend/Dockerfile.my.bak
38+
# Create temporary Dockerfile with target Python version
39+
sed "s/FROM python:3.10/FROM python:${{ matrix.python-version }}/g" ruoyi-fastapi-backend/Dockerfile.my.bak > ruoyi-fastapi-backend/Dockerfile.my
40+
41+
- name: Start services with docker-compose
42+
run: |
43+
cd ruoyi-fastapi-test
44+
docker compose -f docker-compose.test.my.yml up -d --build
45+
46+
- name: Wait for services to be ready
47+
run: |
48+
cd ruoyi-fastapi-test
49+
# Wait for backend to be running
50+
timeout 180 bash -c 'until docker compose -f docker-compose.test.my.yml ps ruoyi-backend-my | grep -q "Up"; do sleep 5; done'
51+
# Wait for frontend to be running
52+
timeout 120 bash -c 'until docker compose -f docker-compose.test.my.yml ps ruoyi-frontend | grep -q "Up"; do sleep 5; done'
53+
# Additional wait for services to be fully ready and listening on ports
54+
sleep 30
55+
# Check that backend is actually responding on the API endpoint
56+
echo "Checking if backend service is ready..."
57+
for i in {1..30}; do
58+
if curl -f http://localhost:9099/captchaImage > /dev/null 2>&1; then
59+
echo "Backend service is ready!"
60+
break
61+
fi
62+
echo "Waiting for backend service to be ready... ($i/30)"
63+
sleep 5
64+
done
65+
# Final check
66+
if ! curl -f http://localhost:9099/captchaImage > /dev/null 2>&1; then
67+
echo "Backend service failed to start properly. Checking logs..."
68+
docker logs ruoyi-backend-my-test
69+
exit 1
70+
fi
71+
72+
- name: Run tests
73+
run: |
74+
cd ruoyi-fastapi-test
75+
pip install -r requirements.txt
76+
playwright install
77+
pytest -v
78+
79+
- name: Stop services
80+
if: always()
81+
run: |
82+
cd ruoyi-fastapi-test
83+
docker compose -f docker-compose.test.my.yml down
84+
85+
- name: Restore original Dockerfile.my
86+
if: always()
87+
run: |
88+
# Restore original Dockerfile.my after test
89+
mv ruoyi-fastapi-backend/Dockerfile.my.bak ruoyi-fastapi-backend/Dockerfile.my
90+
91+
pg-test:
92+
runs-on: ubuntu-latest
93+
strategy:
94+
fail-fast: false
95+
matrix:
96+
python-version: ["3.9", "3.10", "3.11", "3.12"]
97+
98+
steps:
99+
- uses: actions/checkout@v5
100+
101+
- name: Set up Python ${{ matrix.python-version }}
102+
uses: actions/setup-python@v5
103+
with:
104+
python-version: ${{ matrix.python-version }}
105+
106+
- name: Cache Docker layers
107+
uses: actions/cache@v5
108+
with:
109+
path: /tmp/.docker_cache
110+
key: ${{ runner.os }}-docker-${{ matrix.python-version }}-${{ hashFiles('**/Dockerfile*', '**/requirements.txt') }}
111+
112+
- name: Set up Docker Buildx
113+
uses: docker/setup-buildx-action@v3
114+
115+
- name: Create temporary Dockerfile with Python ${{ matrix.python-version }}
116+
run: |
117+
# Save original Dockerfile.my
118+
cp ruoyi-fastapi-backend/Dockerfile.my ruoyi-fastapi-backend/Dockerfile.my.bak
119+
# Create temporary Dockerfile with target Python version
120+
sed "s/FROM python:3.10/FROM python:${{ matrix.python-version }}/g" ruoyi-fastapi-backend/Dockerfile.my.bak > ruoyi-fastapi-backend/Dockerfile.my
121+
122+
- name: Start services with docker-compose
123+
run: |
124+
cd ruoyi-fastapi-test
125+
docker compose -f docker-compose.test.pg.yml up -d --build
126+
127+
- name: Wait for services to be ready
128+
run: |
129+
cd ruoyi-fastapi-test
130+
# Wait for backend to be running
131+
timeout 180 bash -c 'until docker compose -f docker-compose.test.pg.yml ps ruoyi-backend-my | grep -q "Up"; do sleep 5; done'
132+
# Wait for frontend to be running
133+
timeout 120 bash -c 'until docker compose -f docker-compose.test.pg.yml ps ruoyi-frontend | grep -q "Up"; do sleep 5; done'
134+
# Additional wait for services to be fully ready and listening on ports
135+
sleep 30
136+
# Check that backend is actually responding on the API endpoint
137+
echo "Checking if backend service is ready..."
138+
for i in {1..30}; do
139+
if curl -f http://localhost:9099/captchaImage > /dev/null 2>&1; then
140+
echo "Backend service is ready!"
141+
break
142+
fi
143+
echo "Waiting for backend service to be ready... ($i/30)"
144+
sleep 5
145+
done
146+
# Final check
147+
if ! curl -f http://localhost:9099/captchaImage > /dev/null 2>&1; then
148+
echo "Backend service failed to start properly. Checking logs..."
149+
docker logs ruoyi-backend-pg-test
150+
exit 1
151+
fi
152+
153+
- name: Run tests
154+
run: |
155+
cd ruoyi-fastapi-test
156+
pip install -r requirements.txt
157+
playwright install
158+
pytest -v
159+
160+
- name: Stop services
161+
if: always()
162+
run: |
163+
cd ruoyi-fastapi-test
164+
docker compose -f docker-compose.test.pg.yml down
165+
166+
- name: Restore original Dockerfile.my
167+
if: always()
168+
run: |
169+
# Restore original Dockerfile.my after test
170+
mv ruoyi-fastapi-backend/Dockerfile.my.bak ruoyi-fastapi-backend/Dockerfile.my

.github/workflows/ruff.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Ruff Check
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
lint-format:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v5
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: "3.9"
19+
20+
- name: Install dependencies
21+
run: |
22+
python -m pip install --upgrade pip
23+
pip install ruff
24+
25+
- name: Run linting
26+
run: |
27+
ruff check ruoyi-fastapi-backend
28+
ruff check ruoyi-fastapi-test
29+
30+
- name: Run format check
31+
run: |
32+
ruff format ruoyi-fastapi-backend --check
33+
ruff format ruoyi-fastapi-test --check

.github/workflows/test.yml

Lines changed: 0 additions & 113 deletions
This file was deleted.

ruoyi-fastapi-test/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ cd ruoyi-fastapi-test
5656
#### 启动 Docker 服务
5757

5858
```bash
59-
docker compose -f docker-compose.test.yml up -d
59+
# MySQL版本
60+
docker compose -f docker-compose.test.my.yml up -d --build
61+
# PostgreSQL版本
62+
docker compose -f docker-compose.test.pg.yml up -d --build
6063
```
6164

6265
#### 运行测试
@@ -102,7 +105,7 @@ python -m pytest -v
102105

103106
## 配置说明
104107

105-
默认使用 `docker-compose.test.yml` (MySQL版本) 启动服务,前端端口为 `80`,后端端口为 `9099`。测试环境已禁用验证码功能。
108+
使用 `docker-compose.test.my.yml``docker-compose.test.pg.yml`启动服务,默认前端端口为 `80`,后端端口为 `9099`。测试环境已禁用验证码功能。
106109

107110
## 注意事项
108111

ruoyi-fastapi-test/docker-compose.test.yml renamed to ruoyi-fastapi-test/docker-compose.test.my.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ services:
2121
context: ../ruoyi-fastapi-backend
2222
dockerfile: Dockerfile.my
2323
image: ruoyi-backend-my:latest
24-
container_name: ruoyi-backend-test
24+
container_name: ruoyi-backend-my-test
2525
ports:
2626
- "9099:9099"
2727
depends_on:
@@ -31,9 +31,6 @@ services:
3131
condition: service_healthy
3232
networks:
3333
- ruoyi-network-test
34-
environment:
35-
# 使用测试环境配置,禁用验证码
36-
- SYS_CAPTCHA_ENABLED=false
3734

3835
# MySQL服务
3936
ruoyi-mysql:

0 commit comments

Comments
 (0)