Nixify io and memory tests (#1538)
* Include tests for io and memory in the Nix environment. * include spec tests in nix-shell by default * install the io and memory tests in CI
This commit is contained in:
+27
-23
@@ -1,7 +1,10 @@
|
||||
#!/bin/sh
|
||||
#!/usr/bin/env bash
|
||||
# Run unit tests for Input/Ouput of PostgREST seen as a black box
|
||||
# with test output in Test Anything Protocol format.
|
||||
#
|
||||
# These tests expect that `postgrest` is on the PATH, as well as `curl` and
|
||||
# `ncat` (from the nmap package in some distribution).
|
||||
#
|
||||
# References:
|
||||
# [1] Test Anything Protocol
|
||||
# https://testanything.org/
|
||||
@@ -12,9 +15,15 @@
|
||||
# [3] List of TCP and UDP port numbers
|
||||
# https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers
|
||||
#
|
||||
set -eu
|
||||
|
||||
export POSTGREST_TEST_CONNECTION=${POSTGREST_TEST_CONNECTION:-"postgres:///postgrest_test"}
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
cd io-tests
|
||||
|
||||
trap "kill 0" int term exit
|
||||
|
||||
# Port for Test PostgREST Server (must match config)
|
||||
pgrPort=49421 # in range 49152–65535: for private or temporary use
|
||||
|
||||
@@ -30,11 +39,11 @@ ko(){ result 'not ok' "- $1"; failedTests=$(( $failedTests + 1 )); }
|
||||
comment(){ echo "# $1"; }
|
||||
|
||||
# Utilities to start/stop test PostgREST server running in the background
|
||||
pgrStart(){ stack exec -- postgrest "$1" >/dev/null & pgrPID="$!"; }
|
||||
pgrStartRead(){ stack exec -- postgrest "$1" >/dev/null < "$2" & pgrPID="$!"; }
|
||||
pgrStart(){ postgrest $1 >/dev/null 2>/dev/null & pgrPID="$!"; }
|
||||
pgrStartRead(){ postgrest $1 <$2 >/dev/null & pgrPID="$!"; }
|
||||
pgrStartStdin(){ postgrest $1 >/dev/null <<< "$2" & pgrPID="$!"; }
|
||||
pgrStarted(){ kill -0 "$pgrPID" 2>/dev/null; }
|
||||
pgrStop(){ kill "$pgrPID" 2>/dev/null; }
|
||||
pgrStopAll(){ pkill -f "$(stack path --local-install-root)/bin/postgrest"; }
|
||||
pgrStop(){ kill "$pgrPID" 2>/dev/null; pgrPID=""; }
|
||||
|
||||
# Utilities to send HTTP requests to the PostgREST server
|
||||
rootStatus(){
|
||||
@@ -47,10 +56,6 @@ authorsStatus(){
|
||||
"http://localhost:$pgrPort/authors_only"
|
||||
}
|
||||
|
||||
# Start and End of Unit Tests
|
||||
setUp(){ pgrStopAll; }
|
||||
cleanUp(){ pgrStopAll; }
|
||||
|
||||
# Unit Test Templates
|
||||
readSecretFromFile(){
|
||||
case "$1" in
|
||||
@@ -82,9 +87,9 @@ readSecretFromFile(){
|
||||
pgrStop
|
||||
}
|
||||
|
||||
readDbUriFromFile(){
|
||||
readDbUriFromStdin(){
|
||||
pgrConfig="dburi-from-file.config"
|
||||
pgrStartRead "./configs/$pgrConfig" "./dburis/$1"
|
||||
pgrStartStdin "./configs/$pgrConfig" "$1"
|
||||
while pgrStarted && test "$( rootStatus )" -ne 200
|
||||
do
|
||||
# wait for the server to start
|
||||
@@ -93,9 +98,9 @@ readDbUriFromFile(){
|
||||
done
|
||||
if pgrStarted
|
||||
then
|
||||
ok "connection with $2 dburi read from a file"
|
||||
ok "connection with $2 dburi read from stdin / a file"
|
||||
else
|
||||
ko "connection with $2 dburi read from a file"
|
||||
ko "connection with $2 dburi read from stdin / a file"
|
||||
fi
|
||||
pgrStop
|
||||
}
|
||||
@@ -109,7 +114,7 @@ reqWithRoleClaimKey(){
|
||||
sleep 0.1 \
|
||||
|| sleep 1 # fallback: subsecond sleep is not standard and may fail
|
||||
done
|
||||
authorsJwt=$(psql -qtAX postgrest_test -c "select jwt.sign('$2', 'reallyreallyreallyreallyverysafe');")
|
||||
authorsJwt=$(psql -qtAX "$POSTGREST_TEST_CONNECTION" -c "select jwt.sign('$2', 'reallyreallyreallyreallyverysafe');")
|
||||
httpStatus="$( authorsStatus "$authorsJwt" )"
|
||||
if test "$httpStatus" -eq $3
|
||||
then
|
||||
@@ -132,10 +137,10 @@ invalidRoleClaimKey(){
|
||||
if pgrStarted
|
||||
then
|
||||
ko "invalid jspath \"$1\": accepted"
|
||||
pgrStop
|
||||
else
|
||||
ok "invalid jspath \"$1\": rejected"
|
||||
fi
|
||||
pgrStop
|
||||
}
|
||||
|
||||
# ensure iat claim is successful in the presence of pgrst time cache, see https://github.com/PostgREST/postgrest/issues/1139
|
||||
@@ -148,7 +153,7 @@ ensureIatClaimWorks(){
|
||||
|| sleep 1 # fallback: subsecond sleep is not standard and may fail
|
||||
done
|
||||
for i in {1..10}; do \
|
||||
iatJwt=$(psql -qtAX postgrest_test -c "select jwt.sign(row_to_json(r), 'reallyreallyreallyreallyverysafe') from ( select 'postgrest_test_author' as role, extract(epoch from now()) as iat) r")
|
||||
iatJwt=$(psql -qtAX "$POSTGREST_TEST_CONNECTION" -c "select jwt.sign(row_to_json(r), 'reallyreallyreallyreallyverysafe') from ( select 'postgrest_test_author' as role, extract(epoch from now()) as iat) r")
|
||||
httpStatus="$( authorsStatus $iatJwt )"
|
||||
if test "$httpStatus" -ne 200
|
||||
then
|
||||
@@ -209,9 +214,7 @@ socketConnection(){
|
||||
test -n "$(command -v curl)" || bailOut 'curl is not available'
|
||||
|
||||
# PRE: postgres must be running
|
||||
psql -l 1>/dev/null 2>/dev/null || bailOut 'postgres is not running'
|
||||
|
||||
setUp
|
||||
psql -l "$POSTGREST_TEST_CONNECTION" 1>/dev/null 2>/dev/null || bailOut 'postgres is not running'
|
||||
|
||||
echo "Running IO tests.."
|
||||
|
||||
@@ -231,8 +234,10 @@ readSecretFromFile ascii.b64 'Base64 (ASCII)'
|
||||
readSecretFromFile utf8.b64 'Base64 (UTF-8)'
|
||||
readSecretFromFile binary.b64 'Base64 (binary)'
|
||||
|
||||
readDbUriFromFile uri.noeol "(no EOL)"
|
||||
readDbUriFromFile uri.txt "(EOL)"
|
||||
eol=$'\x0a'
|
||||
|
||||
readDbUriFromStdin "$POSTGREST_TEST_CONNECTION" "(no EOL)"
|
||||
readDbUriFromStdin "$POSTGREST_TEST_CONNECTION$eol" "(EOL)"
|
||||
|
||||
reqWithRoleClaimKey '.postgrest.a_role' '{"postgrest":{"a_role":"postgrest_test_author"}}' 200
|
||||
reqWithRoleClaimKey '.customObject.manyRoles[1]' '{"customObject":{"manyRoles": ["other", "postgrest_test_author"]}}' 200
|
||||
@@ -250,7 +255,6 @@ invalidRoleClaimKey 1234
|
||||
ensureIatClaimWorks
|
||||
ensureAppSettings
|
||||
|
||||
|
||||
cleanUp
|
||||
trap - int term exit
|
||||
|
||||
exit $failedTests
|
||||
|
||||
Reference in New Issue
Block a user