feat(tools): cleanup scripts and Makefile

This commit is contained in:
2026-02-22 20:33:04 +01:00
parent 85f53eff31
commit 5957ac4789
7 changed files with 166 additions and 152 deletions
+30 -30
View File
@@ -1,48 +1,48 @@
#!/bin/bash
# =============================================================================
# Test Runner for pg_morbac Extension
# =============================================================================
# Runs all tests in order, loading setup data and executing each test file.
# Usage: ./tools/test.sh [database_name]
# =============================================================================
set -e
# test.sh - Run tests against the PostgreSQL extension using psql
# Usage: ./test.sh [database_name] [sql_file]
set -e # Exit immediately if a command exits with a non-zero status
# Database name (default: morbac_test)
DB="${1:-morbac_test}"
SQL_FILE="${2:-pg_morbac.sql}"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
TEST_DIR="$PROJECT_DIR/tests"
echo "======================================"
echo "pg_morbac Extension Test Suite"
echo "======================================"
echo "Database: $DB"
echo ""
if [ ! -f "$PROJECT_DIR/$SQL_FILE" ]; then
echo "Error: SQL file not found: $SQL_FILE" >&2
echo "Run 'make build' to generate the required file" >&2
exit 1
fi
# Install extension
echo "=== Installing Extension ==="
psql -d "$DB" -f "$PROJECT_DIR/pg_morbac.sql"
if [ ! -d "$TEST_DIR" ]; then
echo "Error: test directory not found: $TEST_DIR" >&2
exit 1
fi
# Load common setup
echo ""
echo "=== Loading Test Setup ==="
psql -d "$DB" -f "$TEST_DIR/00_setup.sql"
if ! psql -d "$DB" -c '\q' 2>/dev/null; then
echo "Error: cannot connect to database: $DB" >&2
echo "Ensure the database exists and is accessible" >&2
exit 1
fi
# Run all test files in order
echo ""
echo "=== Running Tests ==="
echo "Testing $SQL_FILE on database $DB"
psql -d "$DB" -f "$PROJECT_DIR/$SQL_FILE" -q
if [ -f "$TEST_DIR/00_setup.sql" ]; then
psql -d "$DB" -f "$TEST_DIR/00_setup.sql" -q
fi
for test_file in "$TEST_DIR"/[0-9][0-9]_*.sql; do
if [ -f "$test_file" ]; then
test_name=$(basename "$test_file" .sql)
echo ""
echo "--- Running: $test_name ---"
psql -d "$DB" -f "$test_file"
echo "Running: $test_name"
psql -d "$DB" -f "$test_file" -q
fi
done
echo ""
echo "======================================"
echo "All Tests Completed"
echo "======================================"
echo "All tests completed"