diff --git a/scripts/selftest.sh b/scripts/selftest.sh index d309aaa..645f5e7 100755 --- a/scripts/selftest.sh +++ b/scripts/selftest.sh @@ -30,11 +30,13 @@ fail() { echo " [失败] $1"; FAILED=1; } note() { echo " [提示] $1"; } # 优先用宿主机 curl;没有则在容器里跑 curl +# OpenIM 所有 API 都要求 operationID 请求头(链路追踪用,每次请求唯一即可) +new_opid() { echo "selftest-$(date +%s%N 2>/dev/null || date +%s)-$RANDOM"; } if command -v curl >/dev/null 2>&1; then - http_post() { curl -s -m 15 -X POST "$1" -H 'Content-Type: application/json' ${TOKEN:+-H "token: $TOKEN"} -d "$2"; } + http_post() { curl -s -m 15 -X POST "$1" -H 'Content-Type: application/json' -H "operationID: $(new_opid)" ${TOKEN:+-H "token: $TOKEN"} -d "$2"; } else note "宿主机无 curl,使用容器化 curl" - http_post() { docker run --rm --network host curlimages/curl:8.10.1 -s -m 15 -X POST "$1" -H 'Content-Type: application/json' ${TOKEN:+-H "token: $TOKEN"} -d "$2"; } + http_post() { docker run --rm --network host curlimages/curl:8.10.1 -s -m 15 -X POST "$1" -H 'Content-Type: application/json' -H "operationID: $(new_opid)" ${TOKEN:+-H "token: $TOKEN"} -d "$2"; } fi json_ok() { echo "$1" | tr -d ' \n' | grep -q '"errCode":0'; }