Save results to test_results file
هذا الالتزام موجود في:
17
test_api.sh
17
test_api.sh
@@ -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"
|
||||
|
||||
المرجع في مشكلة جديدة
حظر مستخدم