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}"
|
BASE_URL="${BASE_URL:-http://localhost:5004}"
|
||||||
TEST_FILE="${1:-test_cases.json}"
|
TEST_FILE="${1:-test_cases.json}"
|
||||||
TIMEOUT="${2:-10}"
|
TIMEOUT="${2:-10}"
|
||||||
|
RESULTS_FILE="${3:-test_results.log}"
|
||||||
INSECURE="${INSECURE:-false}"
|
INSECURE="${INSECURE:-false}"
|
||||||
|
|
||||||
if ! command -v curl >/dev/null 2>&1; then
|
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
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
RESULTS=()
|
||||||
idx=0
|
idx=0
|
||||||
TOTAL=$(jq 'length' "$TEST_FILE")
|
TOTAL=$(jq 'length' "$TEST_FILE")
|
||||||
|
|
||||||
@@ -55,6 +57,16 @@ jq -c '.[]' "$TEST_FILE" | while read -r test; do
|
|||||||
if [[ -n "$body" ]]; then
|
if [[ -n "$body" ]]; then
|
||||||
if ! encoded_body=$(jq -r '@json' <<<"$body" 2>/dev/null); then
|
if ! encoded_body=$(jq -r '@json' <<<"$body" 2>/dev/null); then
|
||||||
echo "[$idx/$TOTAL] $name -> ERROR: Invalid JSON body" >&2
|
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
|
continue
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -152,7 +164,7 @@ jq -c '.[]' "$TEST_FILE" | while read -r test; do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
result=$(jq -n \
|
echo $(jq -n \
|
||||||
--arg name "$name" \
|
--arg name "$name" \
|
||||||
--arg url "$url" \
|
--arg url "$url" \
|
||||||
--arg method "$method" \
|
--arg method "$method" \
|
||||||
@@ -161,7 +173,7 @@ jq -c '.[]' "$TEST_FILE" | while read -r test; do
|
|||||||
--arg latency_ms "$latency_ms" \
|
--arg latency_ms "$latency_ms" \
|
||||||
--arg bytes "$bytes" \
|
--arg bytes "$bytes" \
|
||||||
--arg last_err "$last_err" \
|
--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
|
if [[ "$success" == true ]]; then
|
||||||
echo "[$idx/$TOTAL] $name -> OK (status $http_code, ${latency_ms}ms)"
|
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"
|
rm -f "$temp_resp"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
echo "Results saved to $RESULTS_FILE"
|
||||||
|
|||||||
7
test_results.log
Normal file
7
test_results.log
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{ "name": "get-all-wonders", "url": "https://8d5d5fb6ad9e.ngrok-free.app/api/wonders", "method": "GET", "http_code": 200, "success": true, "latency_ms": 569, "bytes": 1103, "last_err": "" }
|
||||||
|
{ "name": "get-wonder-by-id-1", "url": "https://8d5d5fb6ad9e.ngrok-free.app/api/wonders/1", "method": "GET", "http_code": 200, "success": true, "latency_ms": 419, "bytes": 150, "last_err": "" }
|
||||||
|
{ "name": "get-wonder-by-id-invalid", "url": "https://8d5d5fb6ad9e.ngrok-free.app/api/wonders/abc", "method": "GET", "http_code": 400, "success": true, "latency_ms": 403, "bytes": 54, "last_err": "" }
|
||||||
|
{ "name": "create-wonder", "url": "https://8d5d5fb6ad9e.ngrok-free.app/api/wonders", "method": "POST", "http_code": 201, "success": true, "latency_ms": 584, "bytes": 138, "last_err": "" }
|
||||||
|
{ "name": "update-wonder-1", "url": "https://8d5d5fb6ad9e.ngrok-free.app/api/wonders/1", "method": "PUT", "http_code": 204, "success": true, "latency_ms": 401, "bytes": 0, "last_err": "" }
|
||||||
|
{ "name": "delete-wonder-temp", "url": "https://8d5d5fb6ad9e.ngrok-free.app/api/wonders/6", "method": "DELETE", "http_code": 404, "success": true, "latency_ms": 408, "bytes": 40, "last_err": "" }
|
||||||
|
{ "name": "get-random-wonder", "url": "https://8d5d5fb6ad9e.ngrok-free.app/api/wonders/random", "method": "GET", "http_code": 200, "success": true, "latency_ms": 406, "bytes": 208, "last_err": "" }
|
||||||
المرجع في مشكلة جديدة
حظر مستخدم