|
| 1 | +#!/usr/bin/env bash |
| 2 | +#MISE description="Run legacy SQL tests (inline test files)" |
| 3 | +#MISE alias="test" |
| 4 | +#USAGE flag "--test <test>" help="Specific test file pattern to run" default="false" |
| 5 | +#USAGE flag "--postgres <version>" help="PostgreSQL version to test against" default="17" { |
| 6 | +#USAGE choices "14" "15" "16" "17" |
| 7 | +#USAGE } |
| 8 | +#USAGE flag "--skip-build" help="Skip build step (use existing release)" default="false" |
| 9 | + |
| 10 | +#!/bin/bash |
| 11 | + |
| 12 | +set -euo pipefail |
| 13 | + |
| 14 | +POSTGRES_VERSION=${usage_postgres} |
| 15 | + |
| 16 | +connection_url=postgresql://${POSTGRES_USER:-$USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB} |
| 17 | +container_name=postgres-${POSTGRES_VERSION} |
| 18 | + |
| 19 | +fail_if_postgres_not_running () { |
| 20 | + containers=$(docker ps --filter "name=^${container_name}$" --quiet) |
| 21 | + if [ -z "${containers}" ]; then |
| 22 | + echo "error: Docker container for PostgreSQL is not running" |
| 23 | + echo "error: Try running 'mise run postgres:up ${container_name}' to start the container" |
| 24 | + exit 65 |
| 25 | + fi |
| 26 | +} |
| 27 | + |
| 28 | +run_test () { |
| 29 | + echo |
| 30 | + echo '###############################################' |
| 31 | + echo "# Running Test: ${1}" |
| 32 | + echo '###############################################' |
| 33 | + echo |
| 34 | + |
| 35 | + cat $1 | docker exec -i ${container_name} psql --variable ON_ERROR_STOP=1 $connection_url -f- |
| 36 | +} |
| 37 | + |
| 38 | +# Setup |
| 39 | +fail_if_postgres_not_running |
| 40 | + |
| 41 | +# Build (optional) |
| 42 | +if [ "$usage_skip_build" = "false" ]; then |
| 43 | + mise run build --force |
| 44 | +fi |
| 45 | + |
| 46 | +mise run reset --force --postgres ${POSTGRES_VERSION} |
| 47 | + |
| 48 | +echo |
| 49 | +echo '###############################################' |
| 50 | +echo '# Installing release/cipherstash-encrypt.sql' |
| 51 | +echo '###############################################' |
| 52 | +echo |
| 53 | + |
| 54 | +# Install |
| 55 | +cat release/cipherstash-encrypt.sql | docker exec -i ${container_name} psql ${connection_url} -f- |
| 56 | + |
| 57 | + |
| 58 | +cat tests/test_helpers.sql | docker exec -i ${container_name} psql ${connection_url} -f- |
| 59 | +cat tests/ore.sql | docker exec -i ${container_name} psql ${connection_url} -f- |
| 60 | +cat tests/ste_vec.sql | docker exec -i ${container_name} psql ${connection_url} -f- |
| 61 | + |
| 62 | + |
| 63 | +if [ $usage_test = "false" ]; then |
| 64 | + find src -type f -path "*_test.sql" | while read -r sql_file; do |
| 65 | + echo $sql_file |
| 66 | + run_test $sql_file |
| 67 | + done |
| 68 | +else |
| 69 | + find src -type f -path "*$usage_test*" | while read -r sql_file; do |
| 70 | + run_test $sql_file |
| 71 | + done |
| 72 | +fi |
| 73 | + |
| 74 | +echo |
| 75 | +echo '###############################################' |
| 76 | +echo "# ✅ALL TESTS PASSED " |
| 77 | +echo '###############################################' |
| 78 | +echo |
0 commit comments