лаба на 4
This commit is contained in:
@@ -26,32 +26,53 @@ restore_services() {
|
||||
|
||||
trap restore_services EXIT
|
||||
|
||||
echo "Waiting for API readiness before testing..."
|
||||
|
||||
api_ready=false
|
||||
|
||||
for attempt in $(seq 1 60); do
|
||||
if curl --silent --fail --max-time 3 \
|
||||
"$BASE_URL/health/ready" > /dev/null; then
|
||||
api_ready=true
|
||||
break
|
||||
fi
|
||||
|
||||
sleep 1
|
||||
done
|
||||
|
||||
if [[ "$api_ready" != "true" ]]; then
|
||||
echo "FAIL: API did not become ready before testing." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
check_status() {
|
||||
local expected="$1"
|
||||
local path="$2"
|
||||
local authorization="${3:-}"
|
||||
|
||||
local status
|
||||
local result actual_status elapsed
|
||||
|
||||
if [[ -n "$authorization" ]]; then
|
||||
status=$(curl --silent --output /dev/null \
|
||||
result=$(curl --silent --output /dev/null \
|
||||
--max-time 12 \
|
||||
--write-out "%{http_code}" \
|
||||
--write-out "%{http_code} %{time_total}" \
|
||||
-H "Authorization: Bearer $authorization" \
|
||||
"$BASE_URL$path")
|
||||
else
|
||||
status=$(curl --silent --output /dev/null \
|
||||
result=$(curl --silent --output /dev/null \
|
||||
--max-time 12 \
|
||||
--write-out "%{http_code}" \
|
||||
--write-out "%{http_code} %{time_total}" \
|
||||
"$BASE_URL$path")
|
||||
fi
|
||||
|
||||
if [[ "$status" != "$expected" ]]; then
|
||||
echo "FAIL: $path expected $expected, got $status" >&2
|
||||
read -r actual_status elapsed <<< "$result"
|
||||
|
||||
if [[ "$actual_status" != "$expected" ]]; then
|
||||
echo "FAIL: $path expected $expected, got $actual_status" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "PASS: $path returned $status"
|
||||
echo "PASS: $path returned $actual_status in ${elapsed}s"
|
||||
}
|
||||
|
||||
echo "Creating a test user and session..."
|
||||
|
||||
Reference in New Issue
Block a user