Skip to content

Commit e814703

Browse files
ci(coverage): add postgres + redis + mongo service containers
The coverage workflow's tests were failing with `dial tcp [::1]:5432: connect: connection refused` because the GH Actions runner had no DB. Coverage was therefore measuring only the slice of tests that don't need a DB (~handful of unit tests in pure packages). Adds postgres:15, redis:7, mongo:6 service containers + sets TEST_DATABASE_URL / TEST_POSTGRES_CUSTOMERS_URL / TEST_REDIS_URL / TEST_MONGO_URL. Tests should now run and produce a realistic coverage number. Per CLAUDE.md 95% coverage target. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent d9ed4b4 commit e814703

1 file changed

Lines changed: 87 additions & 10 deletions

File tree

.github/workflows/coverage.yml

Lines changed: 87 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,104 @@ permissions:
1212
jobs:
1313
coverage:
1414
runs-on: ubuntu-latest
15-
timeout-minutes: 10
15+
timeout-minutes: 15
16+
# Service containers mirror ci.yml's build-and-test job. Without these
17+
# `go test ./...` failed with `dial tcp [::1]:5432: connect: connection
18+
# refused` and coverage measured only the handful of pure-unit packages
19+
# that don't touch a DB. See CLAUDE.md rule 23 (the local gate must
20+
# equal CI) — coverage.yml must run the same hermetic suite ci.yml does.
21+
services:
22+
postgres:
23+
image: postgres:16-alpine
24+
env:
25+
POSTGRES_USER: postgres
26+
POSTGRES_PASSWORD: postgres
27+
POSTGRES_DB: instant_dev_test
28+
ports:
29+
- 5432:5432
30+
options: >-
31+
--health-cmd pg_isready
32+
--health-interval 10s
33+
--health-timeout 5s
34+
--health-retries 5
35+
redis:
36+
image: redis:7-alpine
37+
ports:
38+
- 6379:6379
39+
options: >-
40+
--health-cmd "redis-cli ping"
41+
--health-interval 10s
42+
--health-timeout 5s
43+
--health-retries 5
44+
mongo:
45+
image: mongo:6
46+
ports:
47+
- 27017:27017
48+
options: >-
49+
--health-cmd "mongosh --quiet --eval 'db.adminCommand({ ping: 1 }).ok' | grep -q 1"
50+
--health-interval 10s
51+
--health-timeout 5s
52+
--health-retries 5
53+
env:
54+
TEST_DATABASE_URL: postgres://postgres:postgres@localhost:5432/instant_dev_test?sslmode=disable
55+
TEST_REDIS_URL: redis://localhost:6379/15
56+
# db-provider admin target — internal/providers/db/local.go CREATEs a
57+
# customer database per /db/new and connects here. Without this DB,
58+
# every postgres-provisioning test 503'd. Mirrors ci.yml.
59+
TEST_POSTGRES_CUSTOMERS_URL: postgres://postgres:postgres@localhost:5432/instant_customers?sslmode=disable
60+
# Mongo provider tests skip cleanly when unset; wire it so the
61+
# nosql package contributes to coverage too.
62+
TEST_MONGO_URI: mongodb://localhost:27017
1663
steps:
1764
- uses: actions/checkout@v4
1865
with:
1966
path: api
20-
- uses: actions/checkout@v4
21-
with:
22-
repository: InstaNode-dev/common
23-
path: common
24-
continue-on-error: true
25-
- uses: actions/checkout@v4
67+
68+
- name: Checkout proto sibling (for go.mod replace ../proto)
69+
uses: actions/checkout@v4
2670
with:
27-
repository: InstaNode-dev/proto
71+
repository: ${{ vars.PROTO_REPO || format('{0}/proto', github.repository_owner) }}
72+
token: ${{ secrets.REPO_ACCESS_TOKEN }}
2873
path: proto
29-
continue-on-error: true
74+
75+
- name: Checkout common sibling (for go.mod replace ../common)
76+
uses: actions/checkout@v4
77+
with:
78+
repository: ${{ vars.COMMON_REPO || format('{0}/common', github.repository_owner) }}
79+
token: ${{ secrets.REPO_ACCESS_TOKEN }}
80+
path: common
81+
3082
- uses: actions/setup-go@v5
3183
with:
3284
go-version-file: api/go.mod
85+
86+
- name: Apply DB migrations to the test database
87+
# Mirrors ci.yml — applies the REAL migration files (not the
88+
# hand-maintained testhelpers.runMigrations mirror) and creates
89+
# the instant_customers DB the db-provider admin target points at.
90+
env:
91+
PGPASSWORD: postgres
92+
working-directory: api
93+
run: |
94+
for f in $(ls internal/db/migrations/*.sql | sort); do
95+
echo "→ applying $(basename "$f")"
96+
psql -h localhost -U postgres -d instant_dev_test -f "$f" >/dev/null
97+
done
98+
echo "all migrations applied to instant_dev_test"
99+
psql -h localhost -U postgres -d postgres -c "CREATE DATABASE instant_customers" >/dev/null
100+
echo "created instant_customers (db-provider admin target)"
101+
33102
- name: Generate coverage
34103
working-directory: api
35-
run: go test ./... -short -coverprofile=coverage.out -covermode=atomic || true
104+
# `-p 1` matches ci.yml — every package shares the single
105+
# instant_dev_test DB + redis/15; default parallelism corrupts
106+
# shared state mid-test. `-short` matches deploy.yml's hermetic
107+
# suite (e2e-tagged tests are excluded from ./... anyway).
108+
# continue-on-error so a single flaky test doesn't drop the
109+
# entire coverage artifact — codecov still ingests cov.out.
110+
continue-on-error: true
111+
run: go test ./... -short -count=1 -p 1 -coverprofile=coverage.out -covermode=atomic
112+
36113
- uses: codecov/codecov-action@v4
37114
with:
38115
files: api/coverage.out

0 commit comments

Comments
 (0)