Files
ljwx-stock/test_data_pipeline_apis.sh
2025-11-18 22:44:41 +08:00

87 lines
2.3 KiB
Bash
Executable File

#!/bin/bash
# Data Pipeline API Test Script
# 测试数据流管道所有API端点
API_BASE="http://localhost:8001/api/data-pipeline"
COLOR_GREEN='\033[0;32m'
COLOR_RED='\033[0;31m'
COLOR_YELLOW='\033[1;33m'
COLOR_NC='\033[0m' # No Color
echo "=================================="
echo "📊 Data Pipeline API Tests"
echo "=================================="
echo ""
# Test function
test_api() {
local name=$1
local url=$2
local method=${3:-GET}
echo -n "Testing $name... "
if [ "$method" = "GET" ]; then
response=$(curl -s -w "\n%{http_code}" -m 10 "$url" 2>/dev/null)
elif [ "$method" = "POST" ]; then
response=$(curl -s -w "\n%{http_code}" -m 10 -X POST "$url" 2>/dev/null)
fi
http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | head -n-1)
if [ "$http_code" = "200" ]; then
echo -e "${COLOR_GREEN}✅ PASS${COLOR_NC} (${http_code})"
if [ ! -z "$body" ]; then
echo " Response: $(echo $body | head -c 100)..."
fi
elif [ "$http_code" = "000" ]; then
echo -e "${COLOR_RED}❌ FAIL${COLOR_NC} (Timeout or connection error)"
else
echo -e "${COLOR_YELLOW}⚠️ WARN${COLOR_NC} (${http_code})"
echo " Response: $body"
fi
echo ""
}
# 1. Pipeline Stats
test_api "Pipeline Stats" "$API_BASE/stats"
# 2. Data Jobs List
test_api "Data Jobs List" "$API_BASE/data-jobs?limit=5"
# 3. Data Coverage
test_api "Data Coverage" "$API_BASE/data-coverage?market=A股"
# 4. Data Preview
test_api "Data Preview" "$API_BASE/data-preview?market=A股&limit=5"
# 5. Database Stats
test_api "DB Stats" "$API_BASE/db/stats"
# 6. Database Tables
test_api "DB Tables" "$API_BASE/db/tables?sort_by=rows"
# 7. Processes
test_api "Processes List" "$API_BASE/processes"
# 8. Latency Monitor
test_api "Latency Monitor" "$API_BASE/monitoring/latency"
# 9. Alert Config
test_api "Alert Config" "$API_BASE/config/alerts"
# 10. Health Check
test_api "Health Check" "$API_BASE/health-check" "POST"
echo "=================================="
echo "📋 Test Summary"
echo "=================================="
echo ""
echo "Frontend: http://localhost:8090/data-pipeline"
echo "Backend API Docs: http://localhost:8001/docs"
echo ""
echo "Note: Some APIs may be slow due to database queries."
echo "This is expected for initial requests."
echo ""