tests: minitest + rack-test suite, bin/test with ephemeral Postgres

This commit is contained in:
Sergei Poljanski 2026-07-02 17:32:14 +04:00
commit 43bed98329
Signed by: asxpi
GPG key ID: 4F8851660FA4121B
13 changed files with 456 additions and 2 deletions

19
bin/test Executable file
View file

@ -0,0 +1,19 @@
#!/usr/bin/env bash
# Full test suite against an ephemeral Postgres. Run inside `nix develop`
# (needs initdb/pg_ctl from the dev shell). Without a database you can still
# run `bundle exec rake test` — DB-backed tests skip.
set -euo pipefail
cd "$(dirname "$0")/.."
PORT="${TEST_PG_PORT:-54329}"
TMP="$(mktemp -d)"
trap 'pg_ctl -D "$TMP/pg" stop -m immediate >/dev/null 2>&1 || true; rm -rf "$TMP"' EXIT
initdb -D "$TMP/pg" -A trust -U postgres >/dev/null
printf "unix_socket_directories = ''\nlisten_addresses = '127.0.0.1'\nport = %s\n" "$PORT" \
>> "$TMP/pg/postgresql.conf"
pg_ctl -D "$TMP/pg" -l "$TMP/pg.log" start >/dev/null
createdb -h 127.0.0.1 -p "$PORT" -U postgres asxpio_test
TEST_DATABASE_URL="postgres://postgres@127.0.0.1:$PORT/asxpio_test" \
bundle exec rake test "$@"