added: cli option --dump-config prints loaded config and exits
This is most useful for automated tests for upcoming configuration features. Can also be used for debugging.
This commit is contained in:
committed by
Wolfgang Walther
parent
d218a9eaff
commit
eb46cf2662
@@ -47,6 +47,54 @@ ok(){ result 'ok' "- $1"; }
|
||||
ko(){ result 'not ok' "- $1"; failedTests=$(( $failedTests + 1 )); }
|
||||
comment(){ echo "# $1"; }
|
||||
|
||||
########################
|
||||
# SYNCHRONOUS IO TESTS #
|
||||
########################
|
||||
|
||||
dumpedConfigMatchesExpectation(){
|
||||
# This test compares the dumped config vs. the corresponding file in ./configs/expected.
|
||||
# To be used to test default values, config aliases and environment variables.
|
||||
dump="$(mktemp)"
|
||||
tap(){
|
||||
if test $1 -eq 0; then
|
||||
ok "dump of config file $2 does match expectation"
|
||||
else
|
||||
ko "dump of config file $2 does not match expectation"
|
||||
fi
|
||||
rm -f "$dump"
|
||||
}
|
||||
trap 'tap $? $1; trap - RETURN; return 0' ERR RETURN
|
||||
postgrest --dump-config "$1" > "$dump"
|
||||
diff "$dump" "$2"
|
||||
}
|
||||
|
||||
dumpedConfigIsValid(){
|
||||
# This test compares the dumped config vs. the dumped-reread-redumped config.
|
||||
# Re-reading the dumped config tests the validity of the config format.
|
||||
# Re-dumping this config should yield no difference to the first dump, showing
|
||||
# that the semantics have not changed by dumping.
|
||||
# Note: only dump vs redump must be equal, the original config file can be different,
|
||||
# because of default values, whitespace, and quoting
|
||||
dump="$(mktemp)"
|
||||
redump="$(mktemp)"
|
||||
tap(){
|
||||
if test $1 -eq 0; then
|
||||
ok "dump of config file $2 is valid"
|
||||
else
|
||||
ko "dump of config file $2 is invalid"
|
||||
fi
|
||||
rm -f "$dump" "$redump"
|
||||
}
|
||||
trap 'tap $? $1; trap - RETURN; return 0' ERR RETURN
|
||||
postgrest --dump-config "$1" > "$dump"
|
||||
postgrest --dump-config "$dump" > "$redump"
|
||||
diff "$dump" "$redump"
|
||||
}
|
||||
|
||||
####################
|
||||
# BACKGROUND TESTS #
|
||||
####################
|
||||
|
||||
# Utilities to start/stop test PostgREST server running in the background
|
||||
pgrStart(){
|
||||
# stderr is not piped to /dev/null to catch errors on startup.
|
||||
@@ -309,6 +357,23 @@ psql -l "$POSTGREST_TEST_CONNECTION" 1>/dev/null 2>/dev/null || bailOut 'postgre
|
||||
|
||||
echo "Running IO tests.."
|
||||
|
||||
# run dumpConfigIsValid with as many inputs as possible
|
||||
for cfg in configs/*.config
|
||||
do
|
||||
# ROLE_CLAIM_KEY is only used in one of the config files
|
||||
# using a complex example here, to make sure the quoting works
|
||||
ROLE_CLAIM_KEY='."https://www.example.com/roles"[0].value' \
|
||||
dumpedConfigIsValid "$cfg" \
|
||||
<<< "Y29ubmVjdGlvbl9zdHJpbmc=" # /dev/stdin is read by some config files, one of them expects Base64
|
||||
done
|
||||
|
||||
# run dumpConfigMatchesExpectation with all expectations
|
||||
for exp in configs/expected/*.config
|
||||
do
|
||||
cfg="$(sed -e 's|expected/||' <(echo $exp))"
|
||||
dumpedConfigMatchesExpectation "$cfg" "$exp"
|
||||
done
|
||||
|
||||
socketConnection
|
||||
|
||||
readSecretFromFile word.noeol 'simple (no EOL)'
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
db-uri = "required"
|
||||
db-schema = "required"
|
||||
db-anon-role = "required"
|
||||
@@ -0,0 +1,24 @@
|
||||
db-uri = "required"
|
||||
db-schema = "required"
|
||||
db-anon-role = "required"
|
||||
db-pool = 10
|
||||
db-pool-timeout = 10
|
||||
db-extra-search-path = "public"
|
||||
db-channel = "pgrst"
|
||||
db-channel-enabled = false
|
||||
db-tx-end = "commit"
|
||||
db-prepared-statements = true
|
||||
server-host = "!4"
|
||||
server-port = 3000
|
||||
server-unix-socket = ""
|
||||
server-unix-socket-mode = "660"
|
||||
openapi-server-proxy-uri = ""
|
||||
jwt-secret = ""
|
||||
jwt-aud = ""
|
||||
secret-is-base64 = false
|
||||
role-claim-key = ".\"role\""
|
||||
max-rows = ""
|
||||
pre-request = ""
|
||||
root-spec = ""
|
||||
raw-media-types = ""
|
||||
log-level = "error"
|
||||
@@ -0,0 +1,26 @@
|
||||
db-uri = "tmp_db"
|
||||
db-schema = "multi,tenant,setup"
|
||||
db-anon-role = "root"
|
||||
db-pool = 1
|
||||
db-pool-timeout = 100
|
||||
db-extra-search-path = "public,test"
|
||||
db-channel = "postgrest"
|
||||
db-channel-enabled = true
|
||||
db-tx-end = "rollback-allow-override"
|
||||
db-prepared-statements = false
|
||||
server-host = "0.0.0.0"
|
||||
server-port = 80
|
||||
server-unix-socket = "/tmp/pgrst_io_test.sock"
|
||||
server-unix-socket-mode = "777"
|
||||
openapi-server-proxy-uri = "https://postgrest.org"
|
||||
jwt-secret = "c2VjdXJpdHl0aHJvdWdob2JzY3VyaXR5"
|
||||
jwt-aud = "https://postgrest.org"
|
||||
secret-is-base64 = true
|
||||
role-claim-key = ".\"user\"[0].\"real-role\""
|
||||
max-rows = 1000
|
||||
pre-request = "please_run_fast"
|
||||
root-spec = "openapi_v3"
|
||||
raw-media-types = "application/vnd.pgrst.config"
|
||||
log-level = "info"
|
||||
app.settings.test = "test"
|
||||
app.settings.test2 = "test"
|
||||
@@ -0,0 +1,26 @@
|
||||
db-uri = "tmp_db"
|
||||
db-schema = "multi, tenant,setup"
|
||||
db-anon-role = "root"
|
||||
db-pool = 1
|
||||
db-pool-timeout = 100
|
||||
db-extra-search-path = "public, test"
|
||||
db-channel = "postgrest"
|
||||
db-channel-enabled = true
|
||||
db-tx-end = "rollback-allow-override"
|
||||
db-prepared-statements = false
|
||||
server-host = "0.0.0.0"
|
||||
server-port = 80
|
||||
server-unix-socket = "/tmp/pgrst_io_test.sock"
|
||||
server-unix-socket-mode = "777"
|
||||
openapi-server-proxy-uri = "https://postgrest.org"
|
||||
jwt-secret = "c2VjdXJpdHl0aHJvdWdob2JzY3VyaXR5"
|
||||
jwt-aud = "https://postgrest.org"
|
||||
secret-is-base64 = true
|
||||
role-claim-key = ".user[0].\"real-role\""
|
||||
max-rows = 1000
|
||||
pre-request = "please_run_fast"
|
||||
root-spec = "openapi_v3"
|
||||
raw-media-types = "application/vnd.pgrst.config"
|
||||
log-level = "info"
|
||||
app.settings.test = "test"
|
||||
app.settings.test2 = "test"
|
||||
Reference in New Issue
Block a user