From 4e3c036c0a1d96d7727e4c5663920cfbc372621c Mon Sep 17 00:00:00 2001 From: Mohamed Date: Tue, 7 Oct 2025 07:29:01 +0300 Subject: [PATCH] fix body encoding --- test_api.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/test_api.sh b/test_api.sh index 420d9f9..6f24f59 100644 --- a/test_api.sh +++ b/test_api.sh @@ -51,6 +51,13 @@ jq -c '.[]' "$TEST_FILE" | while read -r test; do retries=$(jq -r '.retries // 0' <<<"$test") follow_location=$(jq -r '.follow_location // false' <<<"$test") + encoded_body="" + if [[ -n "$body" ]]; then + if ! encoded_body=$(jq -r '@json' <<<"$body" 2>/dev/null); then + echo "[$idx/$TOTAL] $name -> ERROR: Invalid JSON body" >&2 + continue + fi + fi CURL_HDR_ARGS=() if jq -e 'type=="object"' <<<"$headers_json" >/dev/null 2>&1; then @@ -143,8 +150,6 @@ jq -c '.[]' "$TEST_FILE" | while read -r test; do cat "$temp_resp" >&2 fi fi - - if (( attempt <= retries )); then sleep 1; continue; else break; fi done result=$(jq -n \ @@ -162,6 +167,10 @@ jq -c '.[]' "$TEST_FILE" | while read -r test; do echo "[$idx/$TOTAL] $name -> OK (status $http_code, ${latency_ms}ms)" else echo "[$idx/$TOTAL] $name -> FAIL (status ${http_code:-n/a}, reason: $last_err)" >&2 + if [[ -s "$temp_resp" ]]; then + echo "Response body:" >&2 + cat "$temp_resp" >&2 + fi fi rm -f "$temp_resp"