diff --git a/test/test-with-pgenvblock.sh b/test/test-with-pgenvblock.sh index 5d72aafd5..4212bdb38 100755 --- a/test/test-with-pgenvblock.sh +++ b/test/test-with-pgenvblock.sh @@ -2,9 +2,43 @@ set -o pipefail shopt -s inherit_errexit -printf >&2 "Checking whether with-pgenvblock.pl works… " +log() { echo >&2 "[test-with-pgenvblock] $*"; } + +log "Testing..." + +log " Testing: specific postgres-related variables..." +if diff \ + <( + env --ignore-environment \ + files/service/with-pgenvblock.pl \ + <(printf "A=1\0PGSSLMODE=2\0C=3\0PGDATABASE=4\0E=5\0NODE_EXTRA_CA_CERTS=5\0G=7") \ + env \ + | tr '\0' '\n' + ) \ + <(cat < expected'" + log "!!!" + exit 1 +fi + +log " Testing: local env + an injected var..." # for the skeptical reader, on the below: # note that the environment setting (with `export`) runs in a subshell, and as such doesn't touch our own environment, # and as such thus also not the environment with-pgenvblock.pl's is launched with; and thus the PGBLA environment variable # that the `env` invocation sees comes from `with-pgenvblock.pl`'s reading of the env block file and nowhere else. -files/service/with-pgenvblock.pl <(export PGBLA=hurray; cat /proc/self/environ) env | grep --quiet '^PGBLA=hurray$' || (printf >&2 "No, it doesn't\n"; false) && printf >&2 "Yes\n" +if files/service/with-pgenvblock.pl <(export PGBLA=hurray; cat /proc/self/environ) env | grep --quiet '^PGBLA=hurray$'; then + log " Passed OK." +else + log " !!! Test failed." + exit 1 +fi + +log "All tests passed OK."