compliance/test_with_curl.sh
gongwenxin 9bd3cb63f3 docker
2025-08-13 09:52:59 +08:00

72 lines
2.3 KiB
Bash
Executable File
Raw 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
# DMS合规性测试工具 - curl测试脚本
# 对应原始命令python run_api_tests.py --base-url http://127.0.0.1:5001/ --dms ./assets/doc/dms/domain.json --stages-dir ./custom_stages --custom-test-cases-dir ./custom_testcases -v -o ./test_reports/
echo "=== DMS合规性测试工具 - API测试 ==="
# 配置变量
API_SERVER="http://localhost:5050"
TARGET_API="http://host.docker.internal:5001/" # Docker内部访问宿主机
OUTPUT_LOG="log_dms_docker.txt"
echo "[信息] 目标API: $TARGET_API"
echo "[信息] API服务器: $API_SERVER"
echo "[信息] 输出日志: $OUTPUT_LOG"
# 创建测试配置JSON
TEST_CONFIG='{
"base-url": "'$TARGET_API'",
"dms": "./assets/doc/dms/domain.json",
"stages-dir": "./custom_stages",
"custom-test-cases-dir": "./custom_testcases",
"verbose": true,
"output": "./test_reports/",
"format": "json",
"generate-pdf": true,
"strictness-level": "CRITICAL",
"ignore-ssl": true
}'
echo "[信息] 测试配置:"
echo "$TEST_CONFIG" | jq . 2>/dev/null || echo "$TEST_CONFIG"
# 执行测试
echo ""
echo "[信息] 开始执行测试..."
echo "[信息] 这可能需要几分钟时间..."
curl -X POST "$API_SERVER/run" \
-H "Content-Type: application/json" \
-d "$TEST_CONFIG" \
-w "\n\n=== HTTP响应信息 ===\nHTTP状态码: %{http_code}\n响应时间: %{time_total}s\n" \
> "$OUTPUT_LOG" 2>&1
# 检查结果
if [ $? -eq 0 ]; then
echo "[成功] 测试完成!"
echo "[信息] 查看详细日志: cat $OUTPUT_LOG"
echo "[信息] 查看测试报告: ls -la test_reports/"
# 显示简要结果
echo ""
echo "=== 测试结果摘要 ==="
if command -v jq >/dev/null 2>&1; then
# 如果有jq格式化显示JSON结果
tail -n +1 "$OUTPUT_LOG" | jq -r '.status // "未知状态"' 2>/dev/null || echo "请查看日志文件获取详细结果"
else
# 没有jq显示原始结果
echo "请查看日志文件: $OUTPUT_LOG"
fi
else
echo "[错误] 测试执行失败"
echo "[信息] 查看错误日志: cat $OUTPUT_LOG"
fi
echo ""
echo "=== 管理命令 ==="
echo "- 查看服务状态: docker-compose ps"
echo "- 查看服务日志: docker-compose logs"
echo "- 查看测试日志: cat $OUTPUT_LOG"
echo "- 查看测试报告: ls -la test_reports/"