ci(quality): 后端测试 - 备齐 Postgres/Redis 依赖并禁止依赖用例静默跳过 (#571)
Original-Commit: 6bc6d5701f461a7306fd8171e18968c95d7da124 ci(quality): 后端测试 - 备齐 Postgres/Redis 依赖并禁止依赖用例静默跳过 Backend job 既没有 services 也没有 CANVAS_TEST_POSTGRES_DSN,也没装 redis-server, 于是 5 个用例默认静默跳过:PostgreSQL 迁移、素材字节修复、画布版本历史、Redis 租约、 缓存白名单——这些路径在 CI 上从来没被执行过,而 go test ./... 是全绿的。 - 起 postgres:16-alpine service(pg_isready 健康检查)+ 导出 CANVAS_TEST_POSTGRES_DSN; - 安装 redis-server 可执行文件(用例自起临时实例)并停掉系统服务; - 新增守卫:单独跑这 5 个用例,出现 --- SKIP 就 ::error:: 并失败; - 保留既有的 go test -json | tee 与 timings artifact 上传。
This commit is contained in:
1 parent
9dd8c954d0
commit
6d0a459c4f
1 file changed
+35
@@ -14,6 +14,24 @@ jobs:
|
|||||||
defaults:
|
defaults:
|
||||||
run:
|
run:
|
||||||
working-directory: backend
|
working-directory: backend
|
||||||
|
# 后端有 5 个用例默认会静默跳过:3 个需要 CANVAS_TEST_POSTGRES_DSN(PostgreSQL 迁移、
|
||||||
|
# 素材字节修复、画布版本历史),2 个用 exec.LookPath("redis-server") 自起临时实例
|
||||||
|
# (Redis 租约、缓存白名单)。只跑 go test ./... 而不备齐这两样,这些路径永远不会被执行。
|
||||||
|
services:
|
||||||
|
postgres:
|
||||||
|
image: postgres:16-alpine
|
||||||
|
env:
|
||||||
|
POSTGRES_PASSWORD: canvas_test
|
||||||
|
POSTGRES_DB: canvas_test
|
||||||
|
ports:
|
||||||
|
- 5432:5432
|
||||||
|
options: >-
|
||||||
|
--health-cmd "pg_isready -U postgres"
|
||||||
|
--health-interval 5s
|
||||||
|
--health-timeout 5s
|
||||||
|
--health-retries 12
|
||||||
|
env:
|
||||||
|
CANVAS_TEST_POSTGRES_DSN: postgres://postgres:canvas_test@127.0.0.1:5432/canvas_test?sslmode=disable
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-go@v5
|
- uses: actions/setup-go@v5
|
||||||
@@ -21,6 +39,12 @@ jobs:
|
|||||||
go-version-file: backend/go.mod
|
go-version-file: backend/go.mod
|
||||||
cache-dependency-path: backend/go.sum
|
cache-dependency-path: backend/go.sum
|
||||||
cache: true
|
cache: true
|
||||||
|
- name: Install redis-server for integration tests
|
||||||
|
# 用例自己拉起临时 redis-server(unix socket),所以需要的是可执行文件而不是 redis 服务。
|
||||||
|
run: |
|
||||||
|
sudo apt-get update -qq
|
||||||
|
sudo apt-get install -y -qq redis-server
|
||||||
|
sudo systemctl stop redis-server || true
|
||||||
- name: Check formatting
|
- name: Check formatting
|
||||||
run: test -z "$(gofmt -l .)"
|
run: test -z "$(gofmt -l .)"
|
||||||
- name: Run Go tests
|
- name: Run Go tests
|
||||||
@@ -28,6 +52,17 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
go test -json ./... | tee "$RUNNER_TEMP/go-tests.jsonl"
|
go test -json ./... | tee "$RUNNER_TEMP/go-tests.jsonl"
|
||||||
|
- name: Ensure dependency-backed tests were not skipped
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
set -o pipefail
|
||||||
|
go test ./internal/database/ ./internal/canvas/ ./internal/repository/ ./internal/platform/ ./internal/app/ \
|
||||||
|
-run 'TestPostgresAssetIDMigration|TestRepairAssetBytesPostgres|TestCanvasRevision|TestRuntimeCoordinatorRedisLeasePreservesLongestTTL|TestClearAdminRuntimeCacheUsesRedisWhitelist' \
|
||||||
|
-count=1 -v | tee "$RUNNER_TEMP/dependency-tests.log"
|
||||||
|
if grep -q -- "--- SKIP" "$RUNNER_TEMP/dependency-tests.log"; then
|
||||||
|
echo "::error::依赖外部服务的用例被跳过:请检查 CANVAS_TEST_POSTGRES_DSN 与 redis-server"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
- name: Upload Go test timings
|
- name: Upload Go test timings
|
||||||
if: always()
|
if: always()
|
||||||
uses: actions/upload-artifact@v4
|
uses: actions/upload-artifact@v4
|
||||||
|
|||||||
Reference in new issue
Block a user