Files
homelab-frontend/scripts/test-canary.sh
T
Admin Bot a8d8b17a03
CI / Vet, test, build (push) Successful in 2m5s
CI / Build and push image (push) Successful in 49s
test: add integration test suite + canary deployment script
Integration tests:
- internal/serviceadapter/integration_test.go (8 test cases)
- Tests real gateway: health, routing, 404s, auth flow
- Configurable via GATEWAY_URL, TEST_JWT_TOKEN, SKIP_AUTH_TESTS

Canary deployment script:
- scripts/test-canary.sh: scale→1, test, scale→N on pass
- Keeps 1 pod for debugging on test failure
- Supports custom NAMESPACE, DEPLOYMENT, REPLICAS

Usage:
- Local: ./scripts/test-integration.sh
- Production: GATEWAY_URL=https://api.riotpiao.com ./scripts/test-integration.sh
- Canary: ./scripts/test-canary.sh

Added INTEGRATION_TESTS.md with full documentation.
2026-08-27 11:17:51 -07:00

55 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
# Canary deployment test:
# 1. Scale to 1 pod
# 2. Wait for pod to be ready
# 3. Run integration tests
# 4. If pass, scale to 3 pods
# 5. If fail, keep at 1 pod for debugging
set -e
NAMESPACE=${NAMESPACE:-api}
DEPLOYMENT=${DEPLOYMENT:-api-gateway}
REPLICAS=${REPLICAS:-3}
GATEWAY_URL=${GATEWAY_URL:-https://api.riotpiao.com}
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "CANARY TEST: $DEPLOYMENT"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# Step 1: Scale to 1 pod
echo "[1/4] Scaling to 1 canary pod..."
kubectl -n "$NAMESPACE" scale deploy "$DEPLOYMENT" --replicas=1
kubectl -n "$NAMESPACE" rollout status deploy "$DEPLOYMENT" --timeout=2m
echo "[2/4] Waiting for pod to be ready..."
sleep 5
# Step 2: Run integration tests
echo "[3/4] Running integration tests..."
export GATEWAY_URL="$GATEWAY_URL"
export SKIP_AUTH_TESTS=true
export TEST_TIMEOUT=30
if ! go test -tags integration -v ./internal/serviceadapter -run TestIntegration; then
echo ""
echo "❌ Integration tests FAILED"
echo "Keeping 1 canary pod for debugging."
echo "Pod logs:"
kubectl -n "$NAMESPACE" logs -l app="$DEPLOYMENT" --tail=50
exit 1
fi
echo ""
echo "✅ Integration tests PASSED"
# Step 3: Scale back to full replicas
echo "[4/4] Scaling back to $REPLICAS pods..."
kubectl -n "$NAMESPACE" scale deploy "$DEPLOYMENT" --replicas="$REPLICAS"
kubectl -n "$NAMESPACE" rollout status deploy "$DEPLOYMENT" --timeout=5m
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "✅ Canary test complete. Rollout successful."
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"