-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtest-api.sh
More file actions
73 lines (59 loc) · 1.91 KB
/
test-api.sh
File metadata and controls
73 lines (59 loc) · 1.91 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
#!/bin/bash
# Test script for CKB HTTP API
# Tests all endpoints to ensure they respond with proper JSON
set -e
PORT=8081
BASE_URL="http://localhost:$PORT"
echo "Starting CKB server on port $PORT..."
./ckb serve --port $PORT &
SERVER_PID=$!
# Give server time to start
sleep 2
echo "Testing endpoints..."
# Function to test endpoint
test_endpoint() {
local method=$1
local path=$2
local desc=$3
echo -n "Testing $method $path ($desc)... "
response=$(curl -s -X $method "$BASE_URL$path" -w "\n%{http_code}")
http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | head -n-1)
if [ "$http_code" -ge 200 ] && [ "$http_code" -lt 300 ]; then
echo "OK (HTTP $http_code)"
# Validate JSON
if echo "$body" | jq . > /dev/null 2>&1; then
echo " ✓ Valid JSON response"
else
echo " ✗ Invalid JSON response"
exit 1
fi
else
echo "FAILED (HTTP $http_code)"
echo "Response: $body"
exit 1
fi
}
# Test all GET endpoints
test_endpoint "GET" "/" "Root endpoint"
test_endpoint "GET" "/health" "Health check"
test_endpoint "GET" "/ready" "Readiness check"
test_endpoint "GET" "/status" "System status"
test_endpoint "GET" "/doctor" "Diagnostic checks"
test_endpoint "GET" "/symbol/test-symbol-id" "Get symbol"
test_endpoint "GET" "/search?q=test" "Search symbols"
test_endpoint "GET" "/refs/test-symbol-id" "Find references"
test_endpoint "GET" "/architecture" "Architecture overview"
test_endpoint "GET" "/impact/test-symbol-id" "Impact analysis"
test_endpoint "GET" "/openapi.json" "OpenAPI spec"
# Test POST endpoints
test_endpoint "POST" "/doctor/fix" "Get fix script"
test_endpoint "POST" "/cache/warm" "Warm cache"
test_endpoint "POST" "/cache/clear" "Clear cache"
echo ""
echo "All tests passed! ✓"
# Cleanup
echo "Stopping server..."
kill $SERVER_PID
wait $SERVER_PID 2>/dev/null || true
echo "Done."