test: add self-contained integration environment

Separate schema migrations from environment-specific fixtures, run the full API workflow against a disposable PostgreSQL Testcontainer, and provide seeded development and UI test environments.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Daniel Noulet 2026-09-19 21:11:20 +02:00
parent 6153017b62
commit 6969f79015
18 changed files with 772 additions and 269 deletions

View file

@ -4,7 +4,7 @@ DATABASE_URL ?= postgres://go_guess:go_guess@localhost:5432/go_guess?sslmode=dis
JWT_SECRET ?= local-development-secret-change-me-12345
GOOSE := cd backend && go run github.com/pressly/goose/v3/cmd/goose@v3.26.0
.PHONY: dev db-up db-down migrate migrate-down backend frontend test test-backend test-frontend test-integration lint build
.PHONY: dev db-up db-down migrate migrate-down seed backend frontend frontend-install test test-backend test-frontend test-integration test-env test-env-down lint build
dev:
docker compose up --build
@ -21,13 +21,19 @@ migrate:
migrate-down:
$(GOOSE) -dir migrations postgres "$(DATABASE_URL)" down
seed:
cd backend && DATABASE_URL="$(DATABASE_URL)" APP_ENV="$${APP_ENV:-development}" go run ./cmd/seed
backend:
cd backend && DATABASE_URL="$(DATABASE_URL)" JWT_SECRET="$(JWT_SECRET)" go run ./cmd/api
frontend:
cd frontend && npm run dev
test: test-backend test-frontend
frontend-install:
cd frontend && npm ci
test: frontend-install test-integration test-frontend
test-backend:
cd backend && go test ./...
@ -36,7 +42,14 @@ test-frontend:
cd frontend && npm test
test-integration:
cd backend && TEST_DATABASE_URL="$(DATABASE_URL)" go test -tags=integration ./internal/database/repository
cd backend && go test -tags=integration ./...
test-env:
COMPOSE_PROJECT_NAME=go-guess-test APP_ENV=test DB_PORT=15432 API_PORT=18080 \
WEB_PORT=15173 FRONTEND_URL=http://localhost:15173 docker compose up -d --build
test-env-down:
COMPOSE_PROJECT_NAME=go-guess-test docker compose down -v --remove-orphans
lint:
cd backend && go vet ./...