-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.sh
More file actions
executable file
·148 lines (122 loc) · 4.04 KB
/
Copy pathvalidate.sh
File metadata and controls
executable file
·148 lines (122 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/bash
# Quick Validation Script for RCA Mock Site
# Run this after deployment to verify all endpoints
set -e
# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Get site URL from argument or use default
SITE_URL="${1:-http://localhost:8788}"
# Auto-convert http to https for .pages.dev domains
if [[ "$SITE_URL" =~ ^http://.*\.pages\.dev ]]; then
SITE_URL="${SITE_URL/http:/https:}"
echo "ℹ️ Auto-converted to HTTPS for Cloudflare Pages"
fi
echo "================================================"
echo " RCA Mock Site - Validation Tests"
echo "================================================"
echo ""
echo "Testing site: $SITE_URL"
echo ""
# Test counter
PASSED=0
FAILED=0
# Helper function to test endpoint
test_endpoint() {
local name="$1"
local url="$2"
local expected_status="$3"
echo -n "Testing: $name ... "
response=$(curl -s -w "\n%{http_code}" "$url")
status_code=$(echo "$response" | tail -n 1)
body=$(echo "$response" | sed '$d')
if [ "$status_code" == "$expected_status" ]; then
echo -e "${GREEN}✓ PASS${NC} (Status: $status_code)"
PASSED=$((PASSED + 1))
else
echo -e "${RED}✗ FAIL${NC} (Expected: $expected_status, Got: $status_code)"
FAILED=$((FAILED + 1))
fi
}
# Test 1: Basic success
test_endpoint "Basic API call" "$SITE_URL/api/test" "200"
# Test 2: 500 error
test_endpoint "500 Error simulation" "$SITE_URL/api/test?status=500" "500"
# Test 3: 404 error
test_endpoint "404 Error simulation" "$SITE_URL/api/test?status=404" "404"
# Test 4: 401 error
test_endpoint "401 Auth error" "$SITE_URL/api/test?status=401&errorType=auth" "401"
# Test 5: DB error with 503
test_endpoint "503 DB error" "$SITE_URL/api/test?status=503&errorType=db" "503"
# Test 6: Delay test (check timing)
echo -n "Testing: Artificial delay (2s) ... "
start_time=$(date +%s)
curl -s "$SITE_URL/api/test?delay=2000" > /dev/null
end_time=$(date +%s)
elapsed=$((end_time - start_time))
if [ $elapsed -ge 2 ] && [ $elapsed -le 3 ]; then
echo -e "${GREEN}✓ PASS${NC} (Took ${elapsed}s)"
PASSED=$((PASSED + 1))
else
echo -e "${RED}✗ FAIL${NC} (Expected ~2s, Got ${elapsed}s)"
FAILED=$((FAILED + 1))
fi
# Test 7: Large payload
echo -n "Testing: Large payload (100KB) ... "
response=$(curl -s "$SITE_URL/api/test?size=100")
size=${#response}
if [ $size -gt 90000 ]; then
echo -e "${GREEN}✓ PASS${NC} (Size: $size bytes)"
PASSED=$((PASSED + 1))
else
echo -e "${RED}✗ FAIL${NC} (Expected >90KB, Got $size bytes)"
FAILED=$((FAILED + 1))
fi
# Test 8: Check response headers
echo -n "Testing: Response headers ... "
headers=$(curl -s -I "$SITE_URL/api/test")
if echo "$headers" | grep -q "application/json" && echo "$headers" | grep -q "no-store"; then
echo -e "${GREEN}✓ PASS${NC}"
PASSED=$((PASSED + 1))
else
echo -e "${RED}✗ FAIL${NC} (Missing required headers)"
FAILED=$((FAILED + 1))
fi
# Test 9: Homepage loads
echo -n "Testing: Homepage (/) ... "
status=$(curl -L -s -o /dev/null -w "%{http_code}" "$SITE_URL/")
if [ "$status" == "200" ]; then
echo -e "${GREEN}✓ PASS${NC}"
PASSED=$((PASSED + 1))
else
echo -e "${RED}✗ FAIL${NC} (Status: $status)"
FAILED=$((FAILED + 1))
fi
# Test 10: Large page loads
echo -n "Testing: Large page (/large.html) ... "
status=$(curl -L -s -o /dev/null -w "%{http_code}" "$SITE_URL/large.html")
if [ "$status" == "200" ]; then
echo -e "${GREEN}✓ PASS${NC}"
PASSED=$((PASSED + 1))
else
echo -e "${RED}✗ FAIL${NC} (Status: $status)"
FAILED=$((FAILED + 1))
fi
# Summary
echo ""
echo "================================================"
echo " Test Results"
echo "================================================"
echo -e "Passed: ${GREEN}$PASSED${NC}"
echo -e "Failed: ${RED}$FAILED${NC}"
echo "Total: $((PASSED + FAILED))"
echo ""
if [ $FAILED -eq 0 ]; then
echo -e "${GREEN}✓ All tests passed! Site is ready for load testing.${NC}"
exit 0
else
echo -e "${RED}✗ Some tests failed. Please review above.${NC}"
exit 1
fi