X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=tests%2F_common.sh;h=0f6243027fb92553c89212a9cc5a51f673a33b4f;hb=45c8529b136d8a78a1f7e6059db3a868b9616fe4;hp=cb31ac766e1fe1e3338ded87c26ce9c4c574052c;hpb=0fb8990b502398a1d2316cb9a67bdf4bb0bde7ee;p=tpg%2Fopendispense2.git diff --git a/tests/_common.sh b/tests/_common.sh index cb31ac7..0f62430 100644 --- a/tests/_common.sh +++ b/tests/_common.sh @@ -1,6 +1,7 @@ # # NOTE: Not a script, to be included by scripts # +USER=$(id -un) BASEDIR=rundir/${TESTNAME}/ PORT=22222 @@ -24,6 +25,7 @@ coke_dummy_mode yes EOF echo "# AUTOGENERATED Test ${TESTNAME}" > ${BASEDIR}cfg_items.conf +echo "pseudo 0 0 Test item" >> ${BASEDIR}cfg_items.conf LOG() { echo "TEST ${TESTNAME}: "$* @@ -34,19 +36,24 @@ FAIL() { } TRY_COMMAND() { cmd="$*" + echo ">> $cmd" if ! $cmd ; then FAIL "Command \`$cmd\` failed" fi } -DISPENSE="../dispense -H localhost -P ${PORT}" +DISPENSE="../dispense -f /dev/null -H localhost -P ${PORT}" -LD_LIBRARY_PATH=.. ../dispsrv -f ${BASEDIR}cfg_server.conf --dont-daemonise > ${BASEDIR}server.log 2>&1 & +LD_LIBRARY_PATH=.. ../dispsrv -f ${BASEDIR}cfg_server.conf --dont-daemonise -d 2 > ${BASEDIR}server.log 2>&1 & server_pid=$! cleanup() { - LOG "Killing ${server_pid}" - kill ${server_pid}; true + if pidof dispsrv | grep ${server_pid} > /dev/null; then + LOG "Killing ${server_pid}" + kill ${server_pid}; true + else + LOG "Server already terminated" + fi } trap cleanup EXIT @@ -57,4 +64,17 @@ if ! (echo "" | nc localhost ${PORT}); then LOG "Server not responding on ${PORT}" LOG "Server log contents:" cat ${BASEDIR}server.log + exit 1 +fi + +if [[ "x$USER" == "xroot" ]]; then + FAIL "Running as root" +fi +# Ensure that the database doesn't already contain the current user +# - 1. Protects against running the test against the production database +# - 2. Allows adding the current user as an admin +if $DISPENSE acct "${USER}" 2> /dev/null; then + FAIL "Database contains '$USER', are you running on production?" fi +# Add the current user as an admin +sqlite3 "${BASEDIR}cokebank.db" "INSERT INTO accounts (acct_name,acct_is_admin,acct_uid) VALUES ('${USER}',1,1);"