Save results to test_results file

هذا الالتزام موجود في:
2025-10-07 07:42:23 +03:00
ملتزم من قبل Kamar El-Dawla Shalaby
الأصل 4e3c036c0a
التزام db94de5f72
2 ملفات معدلة مع 22 إضافات و2 حذوفات

عرض الملف

@@ -7,6 +7,7 @@ set -o nounset
BASE_URL="${BASE_URL:-http://localhost:5004}"
TEST_FILE="${1:-test_cases.json}"
TIMEOUT="${2:-10}"
RESULTS_FILE="${3:-test_results.log}"
INSECURE="${INSECURE:-false}"
if ! command -v curl >/dev/null 2>&1; then
@@ -34,6 +35,7 @@ if ! jq -e '.' "$TEST_FILE" >/dev/null 2>&1; then
exit 2
fi
RESULTS=()
idx=0
TOTAL=$(jq 'length' "$TEST_FILE")
@@ -55,6 +57,16 @@ jq -c '.[]' "$TEST_FILE" | while read -r test; do
if [[ -n "$body" ]]; then
if ! encoded_body=$(jq -r '@json' <<<"$body" 2>/dev/null); then
echo "[$idx/$TOTAL] $name -> ERROR: Invalid JSON body" >&2
echo $(jq -n \
--arg name "$name" \
--arg url "$url" \
--arg method "$method" \
--arg http_code "0" \
--argjson success "false" \
--arg latency_ms "0" \
--arg bytes "0" \
--arg last_err "invalid_json_body" \
'{name:$name, url:$url, method:$method, http_code:($http_code|tonumber), success:$success, latency_ms:($latency_ms|tonumber), bytes:($bytes|tonumber), last_err:$last_err}') >> "$RESULTS_FILE"
continue
fi
fi
@@ -152,7 +164,7 @@ jq -c '.[]' "$TEST_FILE" | while read -r test; do
fi
done
result=$(jq -n \
echo $(jq -n \
--arg name "$name" \
--arg url "$url" \
--arg method "$method" \
@@ -161,7 +173,7 @@ jq -c '.[]' "$TEST_FILE" | while read -r test; do
--arg latency_ms "$latency_ms" \
--arg bytes "$bytes" \
--arg last_err "$last_err" \
'{name:$name, url:$url, method:$method, http_code:($http_code|tonumber), success:$success, latency_ms:($latency_ms|tonumber), bytes:($bytes|tonumber), last_err:$last_err}')
'{name:$name, url:$url, method:$method, http_code:($http_code|tonumber), success:$success, latency_ms:($latency_ms|tonumber), bytes:($bytes|tonumber), last_err:$last_err}') >> "$RESULTS_FILE"
if [[ "$success" == true ]]; then
echo "[$idx/$TOTAL] $name -> OK (status $http_code, ${latency_ms}ms)"
@@ -176,3 +188,4 @@ jq -c '.[]' "$TEST_FILE" | while read -r test; do
rm -f "$temp_resp"
done
echo "Results saved to $RESULTS_FILE"