Backend Tests / test (push) Successful in 59s
resetEnv() conditionally set POSTGRES_HOST only when empty. When TestConnect_InvalidCredentials explicitly set it to 'localhost' and then called resetEnv(), the value was preserved because it wasn't empty. This leaked into TestConcurrentQueries, which then tried to connect to localhost:5432 instead of the workflow-configured postgres hostname. Fix: capture the POSTGRES_HOST value at init() time in a package-level variable (savedPOSTGRESHost) and always restore it in resetEnv(), so the correct value is always used regardless of which tests ran before.
70 lines
1.7 KiB
YAML
70 lines
1.7 KiB
YAML
name: Backend Tests
|
|
description: Runs Go tests with PostgreSQL for all backend packages.
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- develop
|
|
pull_request:
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
defaults:
|
|
run:
|
|
shell: sh
|
|
services:
|
|
postgres:
|
|
image: postgres:16-alpine
|
|
env:
|
|
POSTGRES_USER: myuser
|
|
POSTGRES_PASSWORD: mypassword
|
|
POSTGRES_DB: mydb
|
|
options: >-
|
|
--health-cmd pg_isready
|
|
--health-interval 10s
|
|
--health-timeout 5s
|
|
--health-retries 5
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Go
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version: "1.25"
|
|
cache: false
|
|
|
|
- name: Install system deps
|
|
run: apk add --no-cache postgresql-client
|
|
|
|
- name: Wait for PostgreSQL
|
|
run: |
|
|
for i in $(seq 1 30); do
|
|
pg_isready -h postgres -U myuser && break
|
|
sleep 1
|
|
done
|
|
|
|
- name: Create test databases
|
|
run: |
|
|
PGPASSWORD=mypassword psql -h postgres -U myuser -d mydb -c "CREATE DATABASE crussell_test_db;" 2>/dev/null || true
|
|
|
|
- name: Build
|
|
working-directory: backend
|
|
run: go build ./...
|
|
|
|
- name: Vet
|
|
working-directory: backend
|
|
run: go vet ./...
|
|
|
|
- name: Test (all packages)
|
|
working-directory: backend
|
|
run: go test -tags "test,dev" -count=1 -v -timeout 120s ./handlers/... ./auth/... ./mw/... ./internal/... ./db/...
|
|
env:
|
|
POSTGRES_HOST: postgres
|
|
TEST_DB_HOST: postgres
|
|
PGUSER: myuser
|
|
PGPASSWORD: mypassword
|
|
PGDATABASE: mydb
|