feat: enhance integration test workflow with Docker orchestration
- Add .env file inclusion for single source of truth - Update test-integration to build and start all containers - Add health check waiting for database and application - Run tests from host against containerized database - Add test-stop target for manual container cleanup - Improve help text for better clarity
This commit is contained in:
@@ -1,11 +1,19 @@
|
|||||||
.PHONY: help test test-integration test-all build build-force clean rebuild logs test-env-up test-env-down
|
.PHONY: help test test-integration test-all test-stop build build-force clean rebuild logs test-env-up test-env-down
|
||||||
|
|
||||||
|
# Include .env file for environment variables (single source of truth)
|
||||||
|
# Ignore if .env doesn't exist yet
|
||||||
|
ifneq (,$(wildcard ./.env))
|
||||||
|
include .env
|
||||||
|
export
|
||||||
|
endif
|
||||||
|
|
||||||
# Default target
|
# Default target
|
||||||
help:
|
help:
|
||||||
@echo "Available targets:"
|
@echo "Available targets:"
|
||||||
@echo " make test - Run unit tests"
|
@echo " make test - Run unit tests"
|
||||||
@echo " make test-integration - Run integration tests with test mode enabled"
|
@echo " make test-integration - Build containers, start services, run integration tests"
|
||||||
@echo " make test-all - Run all tests"
|
@echo " make test-all - Run all tests"
|
||||||
|
@echo " make test-stop - Stop containers after testing"
|
||||||
@echo " make build - Build and start containers"
|
@echo " make build - Build and start containers"
|
||||||
@echo " make build-force - Force rebuild and start containers"
|
@echo " make build-force - Force rebuild and start containers"
|
||||||
@echo " make clean - Stop and remove containers"
|
@echo " make clean - Stop and remove containers"
|
||||||
@@ -20,8 +28,39 @@ test:
|
|||||||
|
|
||||||
# Run integration tests with test mode enabled (avoids rate limiting)
|
# Run integration tests with test mode enabled (avoids rate limiting)
|
||||||
test-integration:
|
test-integration:
|
||||||
@echo "Running integration tests with TEST_MODE enabled..."
|
@echo "Building containers..."
|
||||||
TEST_MODE=true RATE_LIMIT_ENABLED=false go test ./cmd/server/tests -run TestIntegrationAPI -v -timeout 5m
|
podman compose build
|
||||||
|
@echo "Starting application containers..."
|
||||||
|
podman compose up -d
|
||||||
|
@echo "Waiting for services to be healthy..."
|
||||||
|
@echo "Waiting for database..."
|
||||||
|
@until podman exec bookhoard_db pg_isready -U postgres > /dev/null 2>&1; do \
|
||||||
|
echo " Database not ready yet..."; \
|
||||||
|
sleep 2; \
|
||||||
|
done; \
|
||||||
|
echo " ✓ Database is ready"
|
||||||
|
@echo "Waiting for application..."
|
||||||
|
@sleep 3; \
|
||||||
|
until curl -sf http://localhost:8765/health > /dev/null 2>&1; do \
|
||||||
|
echo " Application not ready yet..."; \
|
||||||
|
sleep 2; \
|
||||||
|
done; \
|
||||||
|
echo " ✓ Application is ready"
|
||||||
|
@echo ""
|
||||||
|
@echo "Running integration tests from host against containerized database..."
|
||||||
|
DATABASE_HOST=localhost \
|
||||||
|
DATABASE_PORT=5432 \
|
||||||
|
DATABASE_USER=postgres \
|
||||||
|
DATABASE_PASSWORD=$(DBPASS) \
|
||||||
|
DATABASE_NAME=bookhoard \
|
||||||
|
JWT_SECRET=$(JWT_SECRET) \
|
||||||
|
TEST_MODE=true \
|
||||||
|
RATE_LIMIT_ENABLED=false \
|
||||||
|
TEST_UPLOAD_PATH=./uploads \
|
||||||
|
go test ./cmd/server/tests -v -timeout 5m
|
||||||
|
@echo ""
|
||||||
|
@echo "✅ Integration tests completed!"
|
||||||
|
@echo "📝 Containers are still running. Use 'podman compose logs' to view logs or 'podman compose down' to stop."
|
||||||
|
|
||||||
# Run all tests
|
# Run all tests
|
||||||
test-all: test test-integration
|
test-all: test test-integration
|
||||||
@@ -58,6 +97,12 @@ test-env-up:
|
|||||||
test-env-down:
|
test-env-down:
|
||||||
podman compose down -v
|
podman compose down -v
|
||||||
|
|
||||||
|
# Stop containers after testing
|
||||||
|
test-stop:
|
||||||
|
@echo "Stopping containers..."
|
||||||
|
podman compose down
|
||||||
|
@echo "✓ Containers stopped"
|
||||||
|
|
||||||
# Verify project guidelines compliance
|
# Verify project guidelines compliance
|
||||||
verify-guidelines:
|
verify-guidelines:
|
||||||
@echo "Running comprehensive project guidelines verification..."
|
@echo "Running comprehensive project guidelines verification..."
|
||||||
|
|||||||
Reference in New Issue
Block a user