github.com/Redstoneguy129/cli@v0.0.0-20230211220159-15dca4e91917/internal/db/test/templates/test.sh (about)

     1  #!/bin/bash
     2  set -euo pipefail
     3  
     4  # TODO: move this dependency to base image
     5  if ! command -v pg_prove &> /dev/null; then
     6      apt-get -qq update
     7      apt-get -qq install postgresql-14-pgtap &> /dev/null
     8  fi
     9  
    10  # temporarily enable pgtap
    11  enable="create extension if not exists pgtap with schema extensions"
    12  notice=$(psql -h localhost -U postgres -p 5432 -d postgres -c "$enable" 2>&1 >/dev/null)
    13  
    14  files=$1
    15  cleanup() {
    16      # save the return code of the script
    17      status=$?
    18      # disable pgtap if previously not enabled
    19      if [ -z "$notice" ]; then
    20          psql -h localhost -U postgres -p 5432 -d postgres -c "drop extension if exists pgtap" 2>&1 >/dev/null
    21      fi
    22      # clean up test files
    23      rm -rf "$files"
    24      # actually quit
    25      exit $status
    26  }
    27  
    28  trap cleanup EXIT
    29  
    30  # run postgres unit tests
    31  pg_prove -h localhost -U postgres --ext .pg --ext .sql -r "$files"