Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions test/test-with-pgenvblock.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF
PGSSLMODE=2
PGDATABASE=4
EOF
)
then
log " Passed OK."
else
log "!!!"
log "!!! Test failed; see above for differences between '< actual' and '> 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"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This structure had to change because it wasn't triggering set -e handling due to its structure:

The shell does not exit if the command that fails is part of ... any command executed in a && or || list except the command following the final && or ||
-https://doc.guix.gnu.org/bash/latest/en/html_node/The-Set-Builtin.html

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."
Loading