🐛 fix: BDD tests PostgreSQL connection using DLC_* environment variables

- Add getPostgresHost() function to use DLC_DATABASE_HOST env var
- Default to dance-lessons-coach-postgres container name
- Update local CI/CD script to set proper DLC_* environment variables
- Fix Docker Compose test execution to pass correct database config
- Ensure BDD tests can connect to PostgreSQL in both Docker and native modes

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
2026-04-07 23:38:27 +02:00
parent f54c60c6a3
commit 9528b7d288
2 changed files with 41 additions and 20 deletions

View File

@@ -3,7 +3,7 @@
# Simulates the CI/CD pipeline but builds Docker image locally
# Use this for local development and testing without Gitea
set -e
set -eu
echo "🚀 Local CI/CD Testing"
echo "======================"
@@ -34,7 +34,7 @@ echo ""
# 2. Calculate dependency hash (match CI workflow)
echo "2. Calculating dependency hash..."
DEPS_HASH=$(sha256sum go.mod go.sum | sha256sum | cut -d' ' -f1 | head -c 12)
export DEPS_HASH=$(sha256sum go.mod go.sum | sha256sum | cut -d' ' -f1 | head -c 12)
echo "Dependency hash: $DEPS_HASH"
echo "✅ Dependency hash calculated"
echo ""
@@ -74,12 +74,13 @@ if [ "$HAS_DOCKER" = true ]; then
sleep 2
done
# Set PostgreSQL environment variables
export PGHOST="dance-lessons-coach-postgres"
export PGPORT=5432
export PGUSER=postgres
export PGPASSWORD=postgres
export PGDATABASE=dance_lessons_coach_bdd_test
# Set PostgreSQL environment variables for BDD tests
export DLC_DATABASE_HOST="dance-lessons-coach-postgres"
export DLC_DATABASE_PORT=5432
export DLC_DATABASE_USER=postgres
export DLC_DATABASE_PASSWORD=postgres
export DLC_DATABASE_NAME=dance_lessons_coach_bdd_test
export DLC_DATABASE_SSL_MODE=disable
else
echo "⚠️ Docker not available - PostgreSQL tests will be skipped"
fi
@@ -101,7 +102,7 @@ echo ""
echo "6. Generating Swagger documentation..."
if [ "$USE_DOCKER_CACHE" = true ]; then
echo "Running in Docker Compose container..."
docker compose -f docker-compose.build.yml exec -w /workspace/pkg/server build-cache sh -c "go generate"
docker compose -f docker-compose.build.yml run -w /workspace/pkg/server build-cache sh -c "go generate"
else
echo "Running natively..."
cd pkg/server && go generate
@@ -114,7 +115,7 @@ echo ""
echo "7. Building and testing..."
if [ "$USE_DOCKER_CACHE" = true ]; then
echo "Running in Docker Compose container..."
docker compose -f docker-compose.build.yml exec -w /workspace build-cache sh -c "go build ./..."
docker compose -f docker-compose.build.yml run -w /workspace build-cache sh -c "go build ./..."
else
echo "Running natively..."
go build ./...
@@ -123,18 +124,26 @@ echo "✅ Code compiled successfully"
if [ "$USE_DOCKER_CACHE" = true ]; then
echo "Running in Docker Compose container with PostgreSQL..."
docker compose -f docker-compose.build.yml exec \
-e PGHOST=dance-lessons-coach-postgres \
-e PGPORT=5432 \
-e PGUSER=postgres \
-e PGPASSWORD=postgres \
-e PGDATABASE=dance_lessons_coach_bdd_test \
docker compose -f docker-compose.build.yml run \
-e DLC_DATABASE_HOST=dance-lessons-coach-postgres \
-e DLC_DATABASE_PORT=5432 \
-e DLC_DATABASE_USER=postgres \
-e DLC_DATABASE_PASSWORD=postgres \
-e DLC_DATABASE_NAME=dance_lessons_coach_bdd_test \
-e DLC_DATABASE_SSL_MODE=disable \
-w /workspace \
build-cache \
sh -c "go test ./... -coverprofile=coverage.out -v && go tool cover -func=coverage.out > coverage.txt"
else
echo "Running natively..."
go test ./... -cover -v
echo "Running natively with Docker Compose PostgreSQL..."
export DLC_DATABASE_HOST=dance-lessons-coach-postgres
export DLC_DATABASE_PORT=5432
export DLC_DATABASE_USER=postgres
export DLC_DATABASE_PASSWORD=postgres
export DLC_DATABASE_NAME=dance_lessons_coach_bdd_test
export DLC_DATABASE_SSL_MODE=disable
go test ./... -coverprofile=coverage.out -v
go tool cover -func=coverage.out > coverage.txt
fi
echo "✅ Tests passed"
echo ""
@@ -143,7 +152,7 @@ echo ""
echo "8. Building binaries..."
if [ "$USE_DOCKER_CACHE" = true ]; then
echo "Running in Docker Compose container..."
docker compose -f docker-compose.build.yml exec -w /workspace build-cache sh -c "./scripts/build.sh"
docker compose -f docker-compose.build.yml run -w /workspace build-cache sh -c "./scripts/build.sh"
else
echo "Running natively..."
./scripts/build.sh