mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-20 10:00:58 +00:00
ci: actually run the PostgreSQL schema and migration tests (#6224)
* ci: actually run the PostgreSQL schema and migration tests TestHostAutoMigrateCreatesColumns_Postgres and TestMigrate_Postgres skip unless XUI_DB_TYPE and XUI_DB_DSN are set. CI sets them only for the durable-first step, so both tests have never run: a green pipeline says nothing about the PostgreSQL schema or the migration path. The job already has a PostgreSQL service. Point those two tests at it and fail if either skips, the same guard the durable-first step uses. * ci: make the PostgreSQL guard fail on a renamed test, and self-test the workflow The guard asserted the absence of `--- SKIP`, which only catches a test that ran and skipped. A renamed or deleted test makes `-run` match nothing, so `go test` prints "no tests to run" and exits 0 — the step stays green while testing nothing, which is the exact failure this PR set out to close. Both steps now count `--- PASS` lines and require the expected number: at least one for durable-first, exactly two for the schema tests. Also adds `.github/workflows/ci.yml` to both `paths` filters so a change to the workflow runs the workflow — without it this PR's own CI never fired and the new step would first execute on main after merge — and hoists the duplicated DSN to job-level `env`. --------- Co-authored-by: n0ctal <n0ctal@users.noreply.github.com>
This commit is contained in:
@@ -8,6 +8,7 @@ on:
|
||||
- "go.sum"
|
||||
- "frontend/**"
|
||||
- ".nvmrc"
|
||||
- ".github/workflows/ci.yml"
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
@@ -17,6 +18,7 @@ on:
|
||||
- "go.sum"
|
||||
- "frontend/**"
|
||||
- ".nvmrc"
|
||||
- ".github/workflows/ci.yml"
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
@@ -53,6 +55,9 @@ jobs:
|
||||
--health-interval 10s
|
||||
--health-timeout 5s
|
||||
--health-retries 5
|
||||
env:
|
||||
XUI_DB_TYPE: postgres
|
||||
XUI_DB_DSN: "host=127.0.0.1 port=5432 user=postgres password=postgres dbname=xui_durable sslmode=disable"
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
- uses: actions/setup-go@v7
|
||||
@@ -64,9 +69,24 @@ jobs:
|
||||
- name: PostgreSQL durable-first tests
|
||||
run: |
|
||||
set -o pipefail
|
||||
XUI_DB_TYPE=postgres XUI_DB_DSN="host=127.0.0.1 port=5432 user=postgres password=postgres dbname=xui_durable sslmode=disable" \
|
||||
go test ./internal/web/service -run 'PostgresCommitFailure' -count=1 -v | tee /tmp/postgres-durable-first.log
|
||||
if grep -q -- '--- SKIP' /tmp/postgres-durable-first.log; then
|
||||
go test ./internal/web/service -run 'PostgresCommitFailure' -count=1 -v | tee /tmp/postgres-durable-first.log
|
||||
# Count passes rather than assert no SKIP: a renamed or deleted test
|
||||
# prints "no tests to run" and exits 0, leaving the step green for nothing.
|
||||
passed=$(grep -c -- '--- PASS' /tmp/postgres-durable-first.log || true)
|
||||
if [ "$passed" -lt 1 ]; then
|
||||
echo "expected at least 1 passing durable-first test, got $passed" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: PostgreSQL schema and migration tests
|
||||
run: |
|
||||
set -o pipefail
|
||||
go test ./internal/database -run '^(TestHostAutoMigrateCreatesColumns_Postgres|TestMigrate_Postgres)$' -count=1 -v | tee /tmp/postgres-schema.log
|
||||
# Both must pass. Counting, not SKIP-matching: renaming either test would
|
||||
# otherwise leave this step green while testing nothing.
|
||||
passed=$(grep -c -- '--- PASS' /tmp/postgres-schema.log || true)
|
||||
if [ "$passed" -lt 2 ]; then
|
||||
echo "expected 2 passing PostgreSQL schema tests, got $passed" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user