Add repeatable PostgreSQL integration tests and configure Vitest, Testing Library, and ESLint. Refs #11 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
46 lines
1.5 KiB
Bash
Executable File
46 lines
1.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
backend_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
managed_tmp="${TMPDIR:-${IDEA_MANAGED_TMP:-}}"
|
|
if [[ -z "$managed_tmp" ]]; then
|
|
echo "TMPDIR or IDEA_MANAGED_TMP must point to a writable managed temp directory" >&2
|
|
exit 2
|
|
fi
|
|
|
|
postgres_home="$managed_tmp/tradarr-embedded-postgres"
|
|
cli="$postgres_home/bin/embedded-postgres"
|
|
export GOCACHE="${GOCACHE:-$managed_tmp/go-build}"
|
|
export GOMODCACHE="${GOMODCACHE:-$managed_tmp/gomodcache}"
|
|
mkdir -p "$postgres_home/bin" "$postgres_home/cache" "$postgres_home/work"
|
|
|
|
if [[ ! -x "$cli" ]]; then
|
|
installer="$postgres_home/install-v2.0.1.sh"
|
|
curl -fsSL https://raw.githubusercontent.com/fergusstrange/embedded-postgres/v2.0.1/install/install.sh -o "$installer"
|
|
EP_VERSION=v2.0.1 EP_INSTALL_DIR="$postgres_home/bin" bash "$installer"
|
|
rm -f "$installer"
|
|
fi
|
|
|
|
version_json="$("$cli" version)"
|
|
if [[ "$version_json" != *'"version":"v2.0.1"'* ]]; then
|
|
echo "Unexpected embedded-postgres CLI version: $version_json" >&2
|
|
exit 2
|
|
fi
|
|
|
|
cd "$backend_dir"
|
|
if [[ -n "${TEST_DATABASE_URL:-}" ]]; then
|
|
TEST_DATABASE_REQUIRED=1 go test ./... -count=1 -v
|
|
exit $?
|
|
fi
|
|
|
|
"$cli" exec \
|
|
--postgres-version 16.15.1 \
|
|
--cache-dir "$postgres_home/cache" \
|
|
--work-dir "$postgres_home/work" \
|
|
-- sh -c 'set -eu
|
|
: "${DATABASE_URL:?embedded-postgres did not set DATABASE_URL}"
|
|
export TEST_DATABASE_REQUIRED=1
|
|
export TEST_DATABASE_URL="$DATABASE_URL"
|
|
unset DATABASE_URL PGHOST PGPORT PGUSER PGPASSWORD PGDATABASE PGSSLMODE
|
|
exec go test ./... -count=1 -v'
|