test(shared-sqs): add quick_test.sh (19 tests), extend hardcore_test.sh (groups 24-28, UI API)

This commit is contained in:
“Naeel”
2026-04-09 19:32:42 +03:00
parent 67817d5480
commit 0ec7c2fbbb
2 changed files with 336 additions and 2 deletions
+176
View File
@@ -0,0 +1,176 @@
#!/bin/bash
# tests/quick_test.sh — Быстрая проверка shared-sqs (smoke test)
# Created: 2026-04-09
# Покрывает: создание тенанта + очереди, send/receive/delete сообщения,
# UI API peek/send/purge, удаление очереди и тенанта.
# Требования: curl, aws CLI, python3
# Запуск:
# bash tests/quick_test.sh
# BASE_URL=https://qu.kube5s.ru ADMIN_TOKEN=... bash tests/quick_test.sh
set -uo pipefail
BASE_URL="${BASE_URL:-https://qu.kube5s.ru}"
ADMIN_TOKEN="${ADMIN_TOKEN:-sqs-admin-7a7d8bd0c060a75c198d48680f34077a}"
REGION="us-east-1"
TS=$(date +%s)
PASS=0
FAIL=0
ok() { echo "$1"; PASS=$((PASS+1)); }
fail() { echo "$1"; FAIL=$((FAIL+1)); }
check() {
local label="$1" body="$2" pattern="$3"
if echo "$body" | grep -qE "$pattern"; then ok "$label"; else fail "$label"; fi
}
check_not() {
local label="$1" body="$2" pattern="$3"
if echo "$body" | grep -qE "$pattern"; then fail "$label"; else ok "$label"; fi
}
check_http() {
local label="$1" want="$2" got="$3"
if [[ "$got" == "$want" ]]; then ok "$label (HTTP $got)"; else fail "$label — ожидалось $want, получено $got"; fi
}
# aws CLI с credentials тенанта
sqs() {
local ak="$1" sk="$2"; shift 2
AWS_ACCESS_KEY_ID="$ak" AWS_SECRET_ACCESS_KEY="$sk" AWS_DEFAULT_REGION="$REGION" \
aws --endpoint-url "$BASE_URL" --output json sqs "$@" 2>&1
}
admin() {
local method="$1" path="$2" body="${3:-}"
if [[ -n "$body" ]]; then
curl -sf --max-time 15 -X "$method" \
-H "Authorization: Bearer $ADMIN_TOKEN" \
-H "Content-Type: application/json" \
-d "$body" "${BASE_URL}${path}" 2>&1
else
curl -sf --max-time 15 -X "$method" \
-H "Authorization: Bearer $ADMIN_TOKEN" \
"${BASE_URL}${path}" 2>&1
fi
}
# ui_api — UI API без авторизации (публичный)
ui() {
local method="$1" path="$2" body="${3:-}"
if [[ -n "$body" ]]; then
curl -sf --max-time 15 -X "$method" \
-H "Content-Type: application/json" \
-d "$body" "${BASE_URL}/ui/api${path}" 2>&1
else
curl -sf --max-time 15 -X "$method" "${BASE_URL}/ui/api${path}" 2>&1
fi
}
echo "════════════════════════════════════════"
echo " shared-sqs Quick Test"
echo " Endpoint: $BASE_URL"
echo "════════════════════════════════════════"
echo ""
# ── 1. Health ──
echo "── 1. Health ──"
R=$(curl -sf --max-time 10 "${BASE_URL}/health" 2>&1)
check "GET /health → OK" "$R" "[Oo][Kk]|status"
R=$(ui GET /health)
check "GET /ui/api/health → ok" "$R" "ok"
echo ""
# ── 2. Создание тенанта ──
echo "── 2. Создание тенанта ──"
RESP=$(admin POST /admin/tenants '{"name":"quick-'"$TS"'","max_queues":5}')
check "POST /admin/tenants → access_key" "$RESP" "access_key"
AK=$(echo "$RESP" | python3 -c "import sys,json; print(json.load(sys.stdin)['access_key'])")
SK=$(echo "$RESP" | python3 -c "import sys,json; print(json.load(sys.stdin)['secret_key'])")
TID=$(echo "$RESP" | python3 -c "import sys,json; print(json.load(sys.stdin)['id'])")
echo " Tenant ID: $TID"
echo " Access Key: $AK"
echo ""
# ── 3. AWS CLI CRUD ──
echo "── 3. AWS CLI CRUD ──"
QNAME="quick-q-$TS"
R=$(sqs "$AK" "$SK" create-queue --queue-name "$QNAME")
check "CreateQueue → QueueUrl" "$R" "QueueUrl"
QURL=$(echo "$R" | python3 -c "import sys,json; print(json.load(sys.stdin)['QueueUrl'])")
R=$(sqs "$AK" "$SK" list-queues)
check "ListQueues → очередь $QNAME в списке" "$R" "$QNAME"
R=$(sqs "$AK" "$SK" send-message --queue-url "$QURL" --message-body "hello-quick-$TS")
check "SendMessage → MessageId" "$R" "MessageId"
R=$(sqs "$AK" "$SK" receive-message --queue-url "$QURL")
check "ReceiveMessage → тело сообщения" "$R" "hello-quick-$TS"
RECEIPT=$(echo "$R" | python3 -c "import sys,json; msgs=json.load(sys.stdin).get('Messages',[]); print(msgs[0]['ReceiptHandle'] if msgs else '')" 2>/dev/null || true)
if [[ -n "$RECEIPT" ]]; then
sqs "$AK" "$SK" delete-message --queue-url "$QURL" --receipt-handle "$RECEIPT" >/dev/null 2>&1
ok "DeleteMessage → без ошибок"
else
fail "DeleteMessage — нет ReceiptHandle"
fi
echo ""
# ── 4. UI API — создание очереди ──
echo "── 4. UI API очереди ──"
R=$(ui POST "/tenants/$TID/queues" '{"name":"ui-quick-q"}')
check "UI POST /queues → создана" "$R" "ui-quick-q"
R=$(ui GET "/tenants/$TID/queues")
check "UI GET /queues → ui-quick-q в списке" "$R" "ui-quick-q"
echo ""
# ── 5. UI API — send/peek/purge ──
echo "── 5. UI API send/peek/purge ──"
R=$(ui POST "/tenants/$TID/queues/ui-quick-q/messages" '{"body":"msg-a"}')
check "UI POST /messages → id" "$R" '"id"'
ui POST "/tenants/$TID/queues/ui-quick-q/messages" '{"body":"msg-b"}' >/dev/null 2>&1
R=$(ui GET "/tenants/$TID/queues/ui-quick-q/messages")
check "UI GET /messages → msg-a" "$R" "msg-a"
check "UI GET /messages → msg-b" "$R" "msg-b"
check_not "UI GET /messages → нет receipt_handle" "$R" "receipt_handle"
# Purge
ui DELETE "/tenants/$TID/queues/ui-quick-q/messages" >/dev/null 2>&1
R=$(ui GET "/tenants/$TID/queues/ui-quick-q/messages")
check_not "UI DELETE /messages (purge) → msg-a исчезло" "$R" "msg-a"
echo ""
# ── 6. UI API — удаление очереди ──
echo "── 6. UI API удаление очереди ──"
HTTP=$(curl -sf --max-time 15 -o /dev/null -w "%{http_code}" -X DELETE \
"${BASE_URL}/ui/api/tenants/${TID}/queues/ui-quick-q")
check_http "UI DELETE /queues/ui-quick-q → 204/200" "204" "$HTTP" 2>/dev/null || \
check_http "UI DELETE /queues/ui-quick-q → 200" "200" "$HTTP"
R=$(ui GET "/tenants/$TID/queues")
check_not "Очередь ui-quick-q исчезла из списка" "$R" "ui-quick-q"
echo ""
# ── 7. AWS CLI DeleteQueue ──
echo "── 7. DeleteQueue ──"
AWS_ACCESS_KEY_ID="$AK" AWS_SECRET_ACCESS_KEY="$SK" AWS_DEFAULT_REGION="$REGION" \
aws --endpoint-url "$BASE_URL" --output json sqs delete-queue --queue-url "$QURL" >/dev/null 2>&1
if [[ $? -eq 0 ]]; then ok "DeleteQueue → без ошибки"; else fail "DeleteQueue → ошибка"; fi
echo ""
# ── Cleanup ──
echo "── Cleanup ──"
admin DELETE "/admin/tenants/$TID" >/dev/null 2>&1 && ok "DELETE тенанта" || fail "DELETE тенанта"
echo ""
echo "════════════════════════════════════════"
printf " Результат: ✅ %d ❌ %d\n" "$PASS" "$FAIL"
echo "════════════════════════════════════════"
[[ $FAIL -eq 0 ]] && exit 0 || exit 1