sless-primer/PG_TEST/test_basic.sh
Repinoid 333093ab6c Add PG_TEST example - PostgreSQL testing suite
Example Terraform configuration for testing PostgreSQL integration:
- main.tf: VPC and database setup
- postgres.tf: Database resource definitions
- outputs.tf: Output values for connection
- test_basic.sh: Basic connectivity tests
- test_lifecycle.sh: Full lifecycle testing
- terraform.tfvars.example: Configuration template
- .gitignore: Ignore sensitive data and terraform artifacts
2026-04-04 08:38:55 +03:00

50 lines
2.0 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# 2026-04-01 — test_basic.sh: простая проверка что ресурсы созданы и outputs заполнены.
# Не делает apply/destroy — только читает state и outputs.
# Запуск: bash test_basic.sh
set -uo pipefail
DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$DIR"
GREEN="\033[0;32m"; RED="\033[0;31m"; NC="\033[0m"
PASS=0; FAIL=0
ok() { echo -e "${GREEN}PASS${NC} $1"; PASS=$((PASS+1)); }
fail() { echo -e "${RED}FAIL${NC} $1"; FAIL=$((FAIL+1)); }
echo "=== PG_TEST basic check — $(date '+%Y-%m-%d %H:%M:%S') ==="
echo ""
# ── 1. Нужные ресурсы есть в state ───────────────────────────────────────────
echo "--- state ---"
for res in \
"nubes_postgres.pg_test_instance" \
"nubes_postgres_user.pg_test_user" \
"nubes_postgres_database.pg_test_db"
do
if terraform state show "$res" > /dev/null 2>&1; then
ok "state: $res"
else
fail "state: $res — не найден"
fi
done
echo ""
# ── 2. Outputs непустые ───────────────────────────────────────────────────────
echo "--- outputs ---"
pg_host=$(terraform output -raw pg_host 2>/dev/null || true)
pg_db=$(terraform output -raw pg_database 2>/dev/null || true)
pg_user=$(terraform output -raw pg_username 2>/dev/null || true)
pg_pass=$(terraform output -raw pg_password 2>/dev/null || true)
[[ -n "$pg_host" ]] && ok "pg_host = $pg_host" || fail "pg_host пустой"
[[ -n "$pg_db" ]] && ok "pg_database = $pg_db" || fail "pg_database пустой"
[[ -n "$pg_user" ]] && ok "pg_username = $pg_user" || fail "pg_username пустой"
[[ -n "$pg_pass" ]] && ok "pg_password непустой" || fail "pg_password пустой (возможно нужен повторный apply)"
echo ""
echo "=== Итог: PASS=$PASS FAIL=$FAIL ==="