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 81 82 83 84 85
|
#!/bin/bash
set -euxo pipefail
# Make sure we're in the right place
test -x ext/test/manage-tinyfs
test -f src/puppetlabs/stockpile/queue.clj
manage_tinyfs="$(pwd)/ext/test/manage-tinyfs"
usage()
{
echo "Usage: $0 [--use-sudo|--no-sudo] [-- LEIN_TEST_ARGS]"
}
tmpdir=''
destroy_tinyfs=''
clean-up()
{
if test "$destroy_tinyfs"; then
as-root "$manage_tinyfs" destroy "$tmpdir"
fi
if test "$tmpdir"; then
rm -rf "$tmpdir"
fi
}
use_sudo=''
while test "$#" -ne 0; do
case "$1" in
--use-sudo)
shift
use_sudo=true
;;
--no-sudo)
shift
use_sudo=''
;;
--)
shift
break
;;
*)
usage 1>&2
exit 1
;;
esac
done
test_tinyfs=''
if test "$(uname -s)" != Linux; then
echo "Not on Linux; skipping root tests" 1>&2
else
if test "$use_sudo"; then
as-root()
{
sudo -i "$@"
}
test_tinyfs=true
elif test "$(id -u)" = 0; then
as-root()
{
"$@"
}
test_tinyfs=true
else
echo "Not root, and --use-sudo not specified; skipping root tests" 1>&2
fi
fi
trap clean-up EXIT
if [ "$test_tinyfs" ]; then
tmpdir="$(mktemp -d "$(pwd)/target/run-test-XXXXXXX")"
destroy_tinyfs=true
as-root "$manage_tinyfs" create "$tmpdir" "$(id -u)" "$(id -g)"
export STOCKPILE_TINY_TEST_FS="$tmpdir/tinyfs"
fi
java -version
# Don't exec or the trap won't fire
lein test "$@"
|