go-platform/scripts/test_storage.sh
2026-04-09 16:26:38 +08:00

94 lines
2.2 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 存储功能测试脚本
echo "================================"
echo "存储功能测试"
echo "================================"
echo ""
# 颜色定义
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# 测试结果
PASS=0
FAIL=0
# 测试函数
test_api() {
local name=$1
local method=$2
local url=$3
local data=$4
echo -n "测试 $name ... "
if [ "$method" = "GET" ]; then
response=$(curl -s -w "\n%{http_code}" "$url")
else
response=$(curl -s -w "\n%{http_code}" -X "$method" -H "Content-Type: application/json" -d "$data" "$url")
fi
http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | head -n-1)
if [ "$http_code" = "200" ] || [ "$http_code" = "201" ]; then
echo -e "${GREEN}✓ PASS${NC}"
PASS=$((PASS + 1))
else
echo -e "${RED}✗ FAIL${NC} (HTTP $http_code)"
echo " 响应: $body"
FAIL=$((FAIL + 1))
fi
}
# 基础URL
BASE_URL="http://localhost:8080"
echo "1. 测试存储配置API"
echo "-------------------"
# 测试获取存储配置
test_api "获取存储配置" "GET" "$BASE_URL/platform/storageConfig"
# 测试保存本地存储配置
test_api "保存本地存储配置" "POST" "$BASE_URL/platform/saveStorageConfig" \
'{"storage_type":"local"}'
echo ""
echo "2. 测试文件上传"
echo "-------------------"
# 创建测试文件
TEST_FILE="/tmp/test_upload.txt"
echo "This is a test file" > "$TEST_FILE"
# 测试文件上传需要认证token这里简化
echo -e "${YELLOW}注意: 文件上传需要认证token请手动测试${NC}"
echo ""
echo "3. 检查数据库表"
echo "-------------------"
# 检查数据库表是否存在需要MySQL连接信息
echo -e "${YELLOW}请手动检查数据库表: yz_system_storage_config${NC}"
echo ""
echo "================================"
echo "测试结果"
echo "================================"
echo -e "通过: ${GREEN}$PASS${NC}"
echo -e "失败: ${RED}$FAIL${NC}"
echo ""
if [ $FAIL -eq 0 ]; then
echo -e "${GREEN}所有测试通过!${NC}"
exit 0
else
echo -e "${RED}部分测试失败,请检查日志${NC}"
exit 1
fi