X-Git-Url: https://git.ucc.asn.au/?p=tpg%2Fopendispense2.git;a=blobdiff_plain;f=tests%2F_common.sh;h=0019b997ec2fd069683e0ddffd8bc7c32c6b0013;hp=fa2f1077f0235c2d7d397f3403874ced12d43382;hb=HEAD;hpb=674c5c0b50247a280a5e6ab0ce1c252579db6407 diff --git a/tests/_common.sh b/tests/_common.sh index fa2f107..0f62430 100644 --- a/tests/_common.sh +++ b/tests/_common.sh @@ -25,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}: "$* @@ -41,13 +42,13 @@ TRY_COMMAND() { 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() { - if pidof dispsrv | grep ${server_pid}; then + if pidof dispsrv | grep ${server_pid} > /dev/null; then LOG "Killing ${server_pid}" kill ${server_pid}; true else @@ -65,3 +66,15 @@ if ! (echo "" | nc localhost ${PORT}); then 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);"