From 86c40e8df90e603f3b8fc8875d3d3d534eb63f0c Mon Sep 17 00:00:00 2001 From: steve-chavez Date: Wed, 22 Jun 2022 19:03:11 -0500 Subject: [PATCH] test: don't run spec tests with stack We cannot handle postgis and other postgresql dependencies with stack. Also delete test/with_tmp_db since it's no longer used. --- .github/workflows/ci.yaml | 12 ----- nix/tools/style.nix | 3 +- test/with_tmp_db | 96 --------------------------------------- 3 files changed, 1 insertion(+), 110 deletions(-) delete mode 100755 test/with_tmp_db diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b8c27f35f..cca70697a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -150,8 +150,6 @@ jobs: cache: | ~/.stack .stack-work - test: true - pgdir: /usr/lib/postgresql artifact: postgrest-ubuntu-x64 - name: MacOS & test @@ -159,8 +157,6 @@ jobs: cache: | ~/.stack .stack-work - test: true - pgdir: /usr/local/Cellar/postgresql artifact: postgrest-macos-x64 - name: Windows @@ -170,8 +166,6 @@ jobs: ~\AppData\Local\Programs\stack .stack-work deps: Add-Content $env:GITHUB_PATH $env:PGBIN - # We'd need to make test/with_tmp_db run on Windows first - # test: true artifact: postgrest-windows-x64 name: Build ${{ matrix.name }} (Stack) @@ -188,12 +182,6 @@ jobs: run: ${{ matrix.deps }} - name: Build with Stack run: stack build --local-bin-path result --copy-bins - - name: Run Spec tests with Stack - if: ${{ matrix.test }} - run: | - postgresql_bin="$(find ${{ matrix.pgdir }} -maxdepth 2 -type d -name bin | head -n 1)" - echo "Using PostgreSQL binaries at $postgresql_bin ..." - PATH="$postgresql_bin:$PATH" test/with_tmp_db stack test - name: Save built executable as artifact uses: actions/upload-artifact@v3 with: diff --git a/nix/tools/style.nix b/nix/tools/style.nix index 7b55c9385..ea986e767 100644 --- a/nix/tools/style.nix +++ b/nix/tools/style.nix @@ -69,8 +69,7 @@ let echo "Linting bash scripts..." ${shellcheck}/bin/shellcheck \ .github/get_cirrusci_freebsd \ - .github/release \ - test/with_tmp_db + .github/release echo "Linting workflows..." ${actionlint}/bin/actionlint diff --git a/test/with_tmp_db b/test/with_tmp_db deleted file mode 100755 index 5808f2226..000000000 --- a/test/with_tmp_db +++ /dev/null @@ -1,96 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -keeptmp=${KEEP_TMP:-""} - -usage() { - cat << EOF - -USAGE: $0 COMMAND - -Runs the given COMMAND with the PGRST_DB_URI environment variable -set to a temporary database that is ready for running the PostgREST test suite. - -You'll need to have the Postgres binaries 'initdb', 'pg_ctl' and 'psql' on your -PATH. - -Example: - - $0 stack test - - # Or, for when inside nix-shell - $0 cabal v2-test - -If KEEP_TMP is set (e.g. to "1"), the temporary directory will not be deleted -after exit. The log files in that directory might be useful for debugging -purposes. - -EOF - exit 1 -} - -if [ "$#" -lt 1 ]; then - echo "Please provide a command to be run with the temporary database." - usage -fi - -# All data will be stored in a temporary directory. -tmpdir="$(mktemp -d)" - -if [ -n "$keeptmp" ]; then - echo "The temporary directory at $tmpdir will be preserved after exit." -else - trap 'rm -rf "$tmpdir"' sigint sigterm exit -fi - -dblog="$tmpdir/db.log" -setuplog="$tmpdir/setup.log" - -log() { - echo "$1" >> "$setuplog" -} - -mkdir -p "$tmpdir"/{db,socket} - -export PGDATA="$tmpdir/db" -export PGHOST="$tmpdir/socket" -export PGUSER=postgrest_test_authenticator -export PGDATABASE=postgres -export DB_URI="postgresql:///$PGDATABASE?host=$PGHOST&user=$PGUSER" -export PGRST_DB_URI="$DB_URI" -export PGRST_DB_SCHEMAS="test" -export PGRST_DB_ANON_ROLE="postgrest_test_anonymous" - -log "Initializing database cluster..." -# We try to make the database cluster as independent as possible from the host -# by specifying the timezone, locale and encoding. -PGTZ=UTC initdb --no-locale --encoding=UTF8 --nosync -U "$PGUSER" --auth=trust \ - >> "$setuplog" - -log "Starting the database cluster..." -# Instead of listening on a local port, we will listen on a unix domain socket. -pg_ctl -l "$dblog" -w start -o "-F -c listen_addresses=\"\" -k $PGHOST" \ - >> "$setuplog" - -stop() { - log "Stopping the database cluster..." - pg_ctl stop -m i >> "$setuplog" - - if [ -n "$keeptmp" ]; then - echo "Keeping the temporary directory at $tmpdir" - else - rm -rf "$tmpdir" - fi -} - -trap stop EXIT - -log "Loading fixtures..." -psql -v ON_ERROR_STOP=1 -f test/spec/fixtures/load.sql >> "$setuplog" - -log "Done. Running command..." -# Run the command that was given as an argument. The `exit` trap above will -# make sure that the database is shut down and the temporary directory is -# deleted when the command is done. This is also why we don't `exec` the -# command - our trap would be lost if we did that. -("$@")