From: John Hodge Date: Mon, 11 Oct 2021 12:45:30 +0000 (+0800) Subject: Tests - Tweaking X-Git-Url: https://git.ucc.asn.au/?p=tpg%2Fopendispense2.git;a=commitdiff_plain;h=1383ba77ec33e94ab104aa2d6bc0c27ec8931727 Tests - Tweaking --- diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7e86b2c..c46648c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -30,4 +30,4 @@ test: - apt update && apt -y install libncurses-dev libmodbus-dev libsqlite3-dev libident netcat sqlite3 - useradd testuser && chown -R testuser . script: - - cd tests && su -l -c './TEST_basic.sh' testuser + - cd tests && su -c './TEST_basic.sh' testuser diff --git a/tests/TEST_basic.sh b/tests/TEST_basic.sh index d128f8d..4636930 100755 --- a/tests/TEST_basic.sh +++ b/tests/TEST_basic.sh @@ -4,21 +4,8 @@ TESTNAME=basic . _common.sh -# (CI runs as root, and root is auto-added by databse creation) -if [[ "x$USER" != "xroot" ]]; then - # Ensure that the databse 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"; then - FAIL "Database contains '$USER'" - 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);" -else - if $DISPENSE acct accmurph; then - FAIL "Database contains 'accmurph' (running as root, might be using prodution)" - fi -fi +TRY_COMMAND "$DISPENSE acct ${USER}" +TRY_COMMAND "$DISPENSE pseudo:0" # Try to add a new user TRY_COMMAND "$DISPENSE user add unittest_user0" diff --git a/tests/_common.sh b/tests/_common.sh index 04d1657..e43a2c8 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}: "$* @@ -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);"