Files

195 lines
6.6 KiB
Bash
Raw Permalink Normal View History

#!/bin/bash
# Comprehensive CURL Functionality Test Script
echo -e "\n========================================"
echo -e " CURL FUNCTIONALITY TESTS"
echo -e "========================================\n"
PASSED=0
PARTIAL=0
FAILED=0
# Test 1: Webapp
echo -e "1. WEBAPP"
echo -e " Testing: http://localhost:3000"
if response=$(curl -s -w "\n%{http_code}" -o /tmp/webapp_response.txt http://localhost:3000 --max-time 5 2>&1); then
http_code=$(echo "$response" | tail -n1)
if [ "$http_code" = "200" ]; then
echo -e " \033[0;32m✅ Status: $http_code\033[0m"
((PASSED++))
else
echo -e " \033[0;33m⚠ Status: $http_code\033[0m"
((PARTIAL++))
fi
else
echo -e " \033[0;31m❌ Error: Connection failed\033[0m"
((FAILED++))
fi
# Test 2: Orchestrator Root
echo -e "\n2. ORCHESTRATOR ROOT"
echo -e " Testing: http://localhost:8080"
if response=$(curl -s -w "\n%{http_code}" -o /tmp/orch_root.txt http://localhost:8080 --max-time 5 2>&1); then
http_code=$(echo "$response" | tail -n1)
if [ "$http_code" = "404" ]; then
echo -e " \033[0;32m✅ Status: 404 (Expected - no root route)\033[0m"
((PASSED++))
else
echo -e " \033[0;33m⚠ Status: $http_code (Expected 404)\033[0m"
((PARTIAL++))
fi
else
echo -e " \033[0;31m❌ Error: Connection failed\033[0m"
((FAILED++))
fi
# Test 3: Health Check
echo -e "\n3. HEALTH CHECK"
echo -e " Testing: http://localhost:8080/health"
if response=$(curl -s -w "\n%{http_code}" -o /tmp/health.json http://localhost:8080/health --max-time 5 2>&1); then
http_code=$(echo "$response" | tail -n1)
if [ "$http_code" = "200" ]; then
echo -e " \033[0;32m✅ Status: $http_code\033[0m"
if command -v jq &> /dev/null; then
status=$(jq -r '.status' /tmp/health.json 2>/dev/null)
db=$(jq -r '.checks.database' /tmp/health.json 2>/dev/null)
memory=$(jq -r '.checks.memory' /tmp/health.json 2>/dev/null)
echo -e " Status: $status"
echo -e " Database: $db"
echo -e " Memory: $memory"
fi
((PASSED++))
elif [ "$http_code" = "503" ]; then
echo -e " \033[0;33m⚠ Status: 503 (Service initializing or database not connected)\033[0m"
((PARTIAL++))
else
echo -e " \033[0;33m⚠ Status: $http_code\033[0m"
((PARTIAL++))
fi
else
echo -e " \033[0;31m❌ Error: Connection failed\033[0m"
((FAILED++))
fi
# Test 4: Metrics
echo -e "\n4. METRICS"
echo -e " Testing: http://localhost:8080/metrics"
if response=$(curl -s -w "\n%{http_code}" -o /tmp/metrics.txt http://localhost:8080/metrics --max-time 5 2>&1); then
http_code=$(echo "$response" | tail -n1)
if [ "$http_code" = "200" ]; then
echo -e " \033[0;32m✅ Status: $http_code\033[0m"
metric_lines=$(grep -v "^#" /tmp/metrics.txt | grep -v "^$" | wc -l)
echo -e " Metrics: $metric_lines lines"
((PASSED++))
else
echo -e " \033[0;33m⚠ Status: $http_code\033[0m"
((PARTIAL++))
fi
else
echo -e " \033[0;31m❌ Error: Connection failed\033[0m"
((FAILED++))
fi
# Test 5: Readiness
echo -e "\n5. READINESS"
echo -e " Testing: http://localhost:8080/ready"
if response=$(curl -s -w "\n%{http_code}" -o /tmp/ready.json http://localhost:8080/ready --max-time 5 2>&1); then
http_code=$(echo "$response" | tail -n1)
if [ "$http_code" = "200" ]; then
echo -e " \033[0;32m✅ Status: $http_code\033[0m"
if command -v jq &> /dev/null; then
ready=$(jq -r '.ready' /tmp/ready.json 2>/dev/null)
echo -e " Ready: $ready"
fi
((PASSED++))
else
echo -e " \033[0;33m⚠ Status: $http_code (May be expected)\033[0m"
((PARTIAL++))
fi
else
echo -e " \033[0;33m⚠ Connection failed (May be expected)\033[0m"
((PARTIAL++))
fi
# Test 6: Liveness
echo -e "\n6. LIVENESS"
echo -e " Testing: http://localhost:8080/live"
if response=$(curl -s -w "\n%{http_code}" -o /tmp/live.json http://localhost:8080/live --max-time 5 2>&1); then
http_code=$(echo "$response" | tail -n1)
if [ "$http_code" = "200" ]; then
echo -e " \033[0;32m✅ Status: $http_code\033[0m"
if command -v jq &> /dev/null; then
alive=$(jq -r '.alive' /tmp/live.json 2>/dev/null)
echo -e " Alive: $alive"
fi
((PASSED++))
else
echo -e " \033[0;33m⚠ Status: $http_code\033[0m"
((PARTIAL++))
fi
else
echo -e " \033[0;31m❌ Error: Connection failed\033[0m"
((FAILED++))
fi
# Test 7: CORS Headers
echo -e "\n7. CORS HEADERS"
echo -e " Testing: http://localhost:8080/health"
if cors_header=$(curl -s -I http://localhost:8080/health --max-time 5 2>&1 | grep -i "access-control-allow-origin"); then
echo -e " \033[0;32m✅ CORS headers present\033[0m"
echo -e " $cors_header"
((PASSED++))
else
echo -e " \033[0;33m⚠ CORS headers not found\033[0m"
((PARTIAL++))
fi
# Test 8: Error Handling
echo -e "\n8. ERROR HANDLING"
echo -e " Testing: http://localhost:8080/api/nonexistent"
if response=$(curl -s -w "\n%{http_code}" -o /tmp/error.txt http://localhost:8080/api/nonexistent --max-time 5 2>&1); then
http_code=$(echo "$response" | tail -n1)
if [ "$http_code" = "404" ]; then
echo -e " \033[0;32m✅ Status: 404 (Proper error handling)\033[0m"
((PASSED++))
else
echo -e " \033[0;33m⚠ Status: $http_code\033[0m"
((PARTIAL++))
fi
else
echo -e " \033[0;33m⚠ Connection failed\033[0m"
((PARTIAL++))
fi
# Test 9: Response Times
echo -e "\n9. RESPONSE TIMES"
endpoints=("http://localhost:3000:Webapp" "http://localhost:8080/health:Health" "http://localhost:8080/metrics:Metrics")
for endpoint_pair in "${endpoints[@]}"; do
url="${endpoint_pair%%:*}"
name="${endpoint_pair##*:}"
start_time=$(date +%s%N)
if curl -s -o /dev/null "$url" --max-time 5 2>&1; then
end_time=$(date +%s%N)
ms=$(( (end_time - start_time) / 1000000 ))
if [ $ms -lt 100 ]; then
color="\033[0;32m"
elif [ $ms -lt 500 ]; then
color="\033[0;33m"
else
color="\033[0;31m"
fi
echo -e " $name: ${color}${ms} ms\033[0m"
else
echo -e " $name: \033[0;31mError\033[0m"
fi
done
# Summary
echo -e "\n========================================"
echo -e " TEST SUMMARY"
echo -e "========================================\n"
echo -e "Total: \033[0;32m$PASSED Passed\033[0m, \033[0;33m$PARTIAL Partial\033[0m, \033[0;31m$FAILED Failed\033[0m"
echo ""