-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path.curl_smoke_tests.sh
More file actions
executable file
·206 lines (182 loc) · 7.81 KB
/
.curl_smoke_tests.sh
File metadata and controls
executable file
·206 lines (182 loc) · 7.81 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/usr/bin/env bash
set -euo pipefail
API=https://yedpdu8io5.execute-api.us-east-1.amazonaws.com/v1
KEY=gHpRowMGemasl3kp73vuv94KLI14f0hU1t5sNDyl
ACCOUNT=550e8400-e29b-41d4-a716-446655440000
IMG=https://s.abcnews.com/images/US/decarlos-brown-ht-jef-250909_1757430530395_hpEmbed_4x5_992.jpg
SCAN_ID=efd2713c-076c-4795-8025-14223ed33b97
HDR=(-H "x-api-key: ${KEY}" -H "x-account-id: ${ACCOUNT}" -H "Content-Type: application/json")
PASS=0
FAIL=0
TOTAL=0
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
test_endpoint() {
local name=$1
local method=$2
local url=$3
local data=$4
local expected_status=$5
local validate_json=$6
TOTAL=$((TOTAL + 1))
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "Test $TOTAL: $name"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "Method: $method"
echo "URL: $url"
# Make request
if [ -n "$data" ]; then
RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" -X "$method" "$url" "${HDR[@]}" -d "$data" 2>&1)
else
RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" -X "$method" "$url" "${HDR[@]}" 2>&1)
fi
# Extract HTTP status and body
HTTP_CODE=$(echo "$RESPONSE" | grep "HTTP_STATUS:" | cut -d: -f2 || echo "000")
BODY=$(echo "$RESPONSE" | sed '/HTTP_STATUS:/d' || echo "")
echo "HTTP Status: $HTTP_CODE"
# Check HTTP status
if [ -z "$HTTP_CODE" ] || [ "$HTTP_CODE" = "000" ]; then
echo -e "${RED}❌ FAIL: No HTTP response received${NC}"
echo "Response: $RESPONSE"
FAIL=$((FAIL + 1))
return 1
fi
# Validate expected status code
if [ "$HTTP_CODE" = "$expected_status" ]; then
echo -e "${GREEN}✅ HTTP Status: $HTTP_CODE (expected $expected_status)${NC}"
else
echo -e "${RED}❌ HTTP Status: $HTTP_CODE (expected $expected_status)${NC}"
FAIL=$((FAIL + 1))
return 1
fi
# Validate JSON if requested
if [ "$validate_json" = "true" ]; then
if echo "$BODY" | jq . >/dev/null 2>&1; then
echo -e "${GREEN}✅ Valid JSON response${NC}"
echo ""
echo "Response body:"
echo "$BODY" | jq . 2>/dev/null || echo "$BODY"
# Additional validations based on endpoint
if [[ "$name" == *"POST /scan"* ]]; then
if echo "$BODY" | jq -e '.scanId' >/dev/null 2>&1; then
export SCAN_ID_FROM_RESPONSE=$(echo "$BODY" | jq -r '.scanId // empty')
if [ -n "$SCAN_ID_FROM_RESPONSE" ]; then
echo -e "${GREEN}✅ Contains scanId: $SCAN_ID_FROM_RESPONSE${NC}"
else
echo -e "${YELLOW}⚠️ Warning: scanId is empty${NC}"
fi
else
echo -e "${YELLOW}⚠️ Warning: No scanId in response${NC}"
fi
fi
if [[ "$name" == *"GET /scans"* ]]; then
if echo "$BODY" | jq -e '.scans' >/dev/null 2>&1; then
SCAN_COUNT=$(echo "$BODY" | jq '.scans | length' 2>/dev/null || echo "0")
echo -e "${GREEN}✅ Contains scans array with $SCAN_COUNT items${NC}"
fi
fi
if [[ "$name" == *"GET /scan"* ]] && [[ "$name" != *"GET /scans"* ]]; then
if echo "$BODY" | jq -e '.scanId' >/dev/null 2>&1; then
echo -e "${GREEN}✅ Contains scanId${NC}"
fi
if echo "$BODY" | jq -e '.status' >/dev/null 2>&1; then
STATUS=$(echo "$BODY" | jq -r '.status' 2>/dev/null || echo "")
echo -e "${GREEN}✅ Contains status: $STATUS${NC}"
fi
fi
else
echo -e "${RED}❌ Invalid JSON response${NC}"
echo "Response body:"
echo "$BODY"
FAIL=$((FAIL + 1))
return 1
fi
else
echo "Response body:"
echo "$BODY" | jq . 2>/dev/null || echo "$BODY"
fi
PASS=$((PASS + 1))
return 0
}
echo "╔══════════════════════════════════════════════════════════════════════════════╗"
echo "║ SPARTAN AI SMOKE TESTS ║"
echo "║ Thermopylae-Stage Environment ║"
echo "╚══════════════════════════════════════════════════════════════════════════════╝"
echo ""
echo "API Base URL: $API"
echo "Account ID: $ACCOUNT"
echo ""
# Test 1: GET /scans
test_endpoint "GET /api/v1/scans" \
"GET" \
"${API}/api/v1/scans?accountID=${ACCOUNT}" \
"" \
"200" \
"true"
# Test 2: PUT /consent
test_endpoint "PUT /api/v1/consent" \
"PUT" \
"${API}/api/v1/consent" \
'{"consent":true}' \
"200" \
"true"
# Test 3: POST /scan
PAYLOAD=$(cat <<JSON
{
"image": "${IMG}",
"metadata": {
"cameraID": "test-cam",
"accountID": "${ACCOUNT}",
"location": {"lat": 37.7749, "lon": -122.4194},
"timestamp": "2025-12-16T12:00:00Z"
}
}
JSON
)
test_endpoint "POST /api/v1/scan" \
"POST" \
"${API}/api/v1/scan" \
"$PAYLOAD" \
"200" \
"true"
# Extract scanId from POST response if available
if [ -n "${SCAN_ID_FROM_RESPONSE:-}" ]; then
SCAN_ID=$SCAN_ID_FROM_RESPONSE
echo -e "${GREEN}Using scanId from POST response: $SCAN_ID${NC}"
fi
# Test 4: GET /scan/{id}
test_endpoint "GET /api/v1/scan/${SCAN_ID}" \
"GET" \
"${API}/api/v1/scan/${SCAN_ID}" \
"" \
"200" \
"true"
# Summary
echo ""
echo "╔══════════════════════════════════════════════════════════════════════════════╗"
echo "║ TEST SUMMARY ║"
echo "╚══════════════════════════════════════════════════════════════════════════════╝"
echo ""
echo "Total Tests: $TOTAL"
echo -e "${GREEN}Passed: $PASS${NC}"
if [ $FAIL -gt 0 ]; then
echo -e "${RED}Failed: $FAIL${NC}"
else
echo -e "${GREEN}Failed: $FAIL${NC}"
fi
echo ""
if [ $FAIL -eq 0 ]; then
echo -e "${GREEN}╔══════════════════════════════════════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ ✅ ALL SMOKE TESTS PASSED ║${NC}"
echo -e "${GREEN}╚══════════════════════════════════════════════════════════════════════════════╝${NC}"
exit 0
else
echo -e "${RED}╔══════════════════════════════════════════════════════════════════════════════╗${NC}"
echo -e "${RED}║ ❌ SOME TESTS FAILED ║${NC}"
echo -e "${RED}╚══════════════════════════════════════════════════════════════════════════════╝${NC}"
exit 1
fi