tests - Support running as `root` (for CI)
[tpg/opendispense2.git] / tests / TEST_basic.sh
1 #!/bin/bash
2 set -eu
3 TESTNAME=basic
4
5 . _common.sh
6
7 # (CI runs as root, and root is auto-added by databse creation)
8 if [[ "$USER" -ne "root" ]]; then
9         # Ensure that the databse doesn't already contain the current user
10         # - 1. Protects against running the test against the production database
11         # - 2. Allows adding the current user as an admin
12         if $DISPENSE acct "$USER"; then
13                 FAIL "Database contains '$USER'"
14         fi
15         # Add the current user as an admin
16         sqlite3 "${BASEDIR}cokebank.db" "INSERT INTO accounts (acct_name,acct_is_admin,acct_uid) VALUES ('${USER}',1,1);"
17 else
18         if $DISPENSE acct accmurph; then
19                 FAIL "Database contains 'accmurph' (running as root, might be using prodution)"
20         fi
21 fi
22
23 # Try to add a new user
24 TRY_COMMAND "$DISPENSE user add unittest_user0"
25
26 # Ensure that the add worked
27 LOG "Checking for test user"
28 TRY_COMMAND $DISPENSE acct unittest_user0 | grep ': $    0.00'
29
30 # Manipulate user's balance
31 TRY_COMMAND $DISPENSE acct unittest_user0 +100 Unit_test
32 TRY_COMMAND $DISPENSE acct unittest_user0 | grep ': $    1.00'
33 TRY_COMMAND $DISPENSE acct unittest_user0 -100 Unit_test
34 TRY_COMMAND $DISPENSE acct unittest_user0 | grep ': $    0.00'
35 LOG "Success"

UCC git Repository :: git.ucc.asn.au