mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-21 18:37:14 +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"
|
- "go.sum"
|
||||||
- "frontend/**"
|
- "frontend/**"
|
||||||
- ".nvmrc"
|
- ".nvmrc"
|
||||||
|
- ".github/workflows/ci.yml"
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
@@ -17,6 +18,7 @@ on:
|
|||||||
- "go.sum"
|
- "go.sum"
|
||||||
- "frontend/**"
|
- "frontend/**"
|
||||||
- ".nvmrc"
|
- ".nvmrc"
|
||||||
|
- ".github/workflows/ci.yml"
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: read
|
contents: read
|
||||||
@@ -53,6 +55,9 @@ jobs:
|
|||||||
--health-interval 10s
|
--health-interval 10s
|
||||||
--health-timeout 5s
|
--health-timeout 5s
|
||||||
--health-retries 5
|
--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:
|
steps:
|
||||||
- uses: actions/checkout@v7
|
- uses: actions/checkout@v7
|
||||||
- uses: actions/setup-go@v7
|
- uses: actions/setup-go@v7
|
||||||
@@ -64,9 +69,24 @@ jobs:
|
|||||||
- name: PostgreSQL durable-first tests
|
- name: PostgreSQL durable-first tests
|
||||||
run: |
|
run: |
|
||||||
set -o pipefail
|
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
|
||||||
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
|
||||||
if grep -q -- '--- SKIP' /tmp/postgres-durable-first.log; then
|
# 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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Vendored
Reference in New Issue
Block a user