1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
#!/usr/bin/env bash
# Run core, integration, and external PuppetDB tests
# Installs ephemeral Leiningen and pgbox executables
# Core and integration tests run in seperate sandboxes
# --pgbin and --pgport required unless set with ext/bin/test-config
set -euo pipefail
usage() { echo 'Usage: $(basename "$0") [--pgbin DIR] [--pgport PORT]'; }
misuse() { usage 1>&2; exit 2; }
declare -A opt
# Validate arguments
while test $# -gt 0; do
case "$1" in
--pgbin|--pgport)
test $# -gt 1 || misuse
opt["${1:2}"]="$2"
shift 2
;;
--)
shift
break
;;
*)
misuse
esac
done
# If pgbin directory is not provided with --pgbin, read ext/test-conf/pgbin
# If pgbin directory cannot be found, exit with error status
if test -z "${opt[pgbin]:-}"; then
opt[pgbin]="$(ext/bin/test-config --get pgbin)"
if test -z "${opt[pgbin]:-}"; then
echo 'Please specify --pgbin or set pgbin with ext/bin/test-config' 1>&2
exit 2
fi
fi
# If pgport number is not provided with --pgport, read ext/test-conf/pgport
# If pgport number cannot be found, exit with error status
if test -z "${opt[pgport]:-}"; then
opt[pgport]="$(ext/bin/test-config --get pgport)"
if test -z "${opt[pgport]:-}"; then
echo 'Please specify --pgport or set pgport with ext/bin/test-config' 1>&2
exit 2
fi
fi
set -x
# Create temporary directory
tmpdir="$(mktemp -d "normal-tests-XXXXXX")"
tmpdir="$(cd "$tmpdir" && pwd)"
trap "$(printf 'rm -rf %q' "$tmpdir")" EXIT
mkdir -p "$tmpdir/local"
# Install Leiningen and pgbox with default versions into temporary directory
ext/bin/require-leiningen default "$tmpdir/local"
ext/bin/require-pgbox default "$tmpdir/local"
# Add to PATH to avoid fetching and installing lein and pgbox multiple times
export PATH="$tmpdir/local/bin:$PATH"
# Run core tests with ephemeral sandboxes
echo -e '\n===== pdb core tests'
ext/bin/boxed-core-tests \
--pgbin "${opt[pgbin]}" --pgport "${opt[pgport]}" \
-- lein test
# Run integration tests with ephemeral sandboxes
echo -e '\n===== pdb integration tests'
ext/bin/boxed-integration-tests \
--pgbin "${opt[pgbin]}" --pgport "${opt[pgport]}" \
-- lein test :integration
# Create a PuppetDB jar and run external tests on it
echo -e '\n===== pdb external tests'
ext/bin/run-external-tests
|