diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml new file mode 100644 index 0000000..ccbbcc8 --- /dev/null +++ b/.github/workflows/e2e.yml @@ -0,0 +1,35 @@ +name: E2E Smoke Tests + +on: + push: + branches: [main, 'devin/**'] + pull_request: + branches: [main, 'devin/**'] + +jobs: + e2e-smoke: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Build and start services + working-directory: src + run: | + docker compose -f docker-compose.e2e.yml up -d --build + echo "Waiting for services to start..." + sleep 30 + + - name: Run smoke tests + run: | + chmod +x tests/e2e/smoke-test.sh + ./tests/e2e/smoke-test.sh + + - name: Show logs on failure + if: failure() + working-directory: src + run: docker compose -f docker-compose.e2e.yml logs + + - name: Cleanup + if: always() + working-directory: src + run: docker compose -f docker-compose.e2e.yml down -v diff --git a/src/docker-compose.e2e.yml b/src/docker-compose.e2e.yml new file mode 100644 index 0000000..5f2fb83 --- /dev/null +++ b/src/docker-compose.e2e.yml @@ -0,0 +1,36 @@ +services: + api-gateway: + build: + context: . + dockerfile: ApiGateway/Dockerfile + ports: + - "5000:5000" + depends_on: + - customer-service + environment: + - ASPNETCORE_ENVIRONMENT=Development + + customer-service: + build: + context: . + dockerfile: Services/Customer/Customer.API/Dockerfile + ports: + - "5002:5002" + depends_on: + - postgres + environment: + - ASPNETCORE_ENVIRONMENT=Development + - ConnectionStrings__DefaultConnection=Host=postgres;Database=customerdb;Username=postgres;Password=postgres + + postgres: + image: postgres:16-alpine + ports: + - "5432:5432" + environment: + POSTGRES_DB: customerdb + POSTGRES_PASSWORD: postgres + volumes: + - postgres_data:/var/lib/postgresql/data + +volumes: + postgres_data: diff --git a/tests/e2e/smoke-test.sh b/tests/e2e/smoke-test.sh new file mode 100755 index 0000000..749f203 --- /dev/null +++ b/tests/e2e/smoke-test.sh @@ -0,0 +1,61 @@ +#!/bin/bash +set -euo pipefail + +GATEWAY_URL="${GATEWAY_URL:-http://localhost:5000}" +CUSTOMER_URL="${CUSTOMER_URL:-http://localhost:5002}" +MAX_RETRIES=30 +RETRY_INTERVAL=5 + +echo "Waiting for gateway to be healthy..." +for i in $(seq 1 $MAX_RETRIES); do + if curl -sf "$GATEWAY_URL/healthz" > /dev/null 2>&1; then + echo "Gateway is healthy!" + break + fi + if [ "$i" -eq "$MAX_RETRIES" ]; then + echo "Gateway failed to become healthy after $((MAX_RETRIES * RETRY_INTERVAL))s" + exit 1 + fi + echo "Attempt $i/$MAX_RETRIES - waiting ${RETRY_INTERVAL}s..." + sleep $RETRY_INTERVAL +done + +echo "" +echo "Waiting for customer-service to be healthy..." +for i in $(seq 1 $MAX_RETRIES); do + if curl -sf "$CUSTOMER_URL/healthz" > /dev/null 2>&1; then + echo "Customer service is healthy!" + break + fi + if [ "$i" -eq "$MAX_RETRIES" ]; then + echo "Customer service failed to become healthy after $((MAX_RETRIES * RETRY_INTERVAL))s" + exit 1 + fi + echo "Attempt $i/$MAX_RETRIES - waiting ${RETRY_INTERVAL}s..." + sleep $RETRY_INTERVAL +done + +echo "" +echo "=== Smoke Test: GET /healthz on customer-service (via direct port) ===" +HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" "$CUSTOMER_URL/healthz") +echo "Response code: $HTTP_CODE" +if [ "$HTTP_CODE" = "200" ]; then + echo "PASS: Customer service health check returns 200" +else + echo "FAIL: Expected 200, got $HTTP_CODE" + exit 1 +fi + +echo "" +echo "=== Smoke Test: GET /api/customers (unauthenticated - expect 401) ===" +HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" "$GATEWAY_URL/api/customers") +echo "Response code: $HTTP_CODE" +if [ "$HTTP_CODE" = "401" ]; then + echo "PASS: Unauthenticated request correctly returns 401" +else + echo "FAIL: Expected 401, got $HTTP_CODE" + exit 1 +fi + +echo "" +echo "All smoke tests passed!"