Add a basic unit test
[tpg/opendispense2.git] / tests / _common.sh
diff --git a/tests/_common.sh b/tests/_common.sh
new file mode 100644 (file)
index 0000000..0019b99
--- /dev/null
@@ -0,0 +1,52 @@
+
+BASEDIR=rundir/${TESTNAME}/
+PORT=22222
+
+mkdir -p ${BASEDIR}
+rm -f ${BASEDIR}cokebank.db
+
+cat << EOF > ${BASEDIR}cfg_server.conf
+# AUTOGENERATED Test ${TESTNAME}
+server_port ${PORT}
+cokebank_database ${BASEDIR}cokebank.db
+items_file ${BASEDIR}cfg_items.conf
+door_serial_port /dev/null
+
+coke_modbus_address 0.0.0.0
+coke_modbus_port 502
+test_mode no
+
+disable_syslog yes
+coke_dummy_mode yes
+EOF
+
+echo "# AUTOGENERATED Test ${TESTNAME}" > ${BASEDIR}cfg_items.conf
+
+LOG() {
+       echo "TEST ${TESTNAME}: "$*
+}
+FAIL() {
+       echo "TEST ${TESTNAME} FAIL: "$*
+       exit 1
+}
+TRY_COMMAND() {
+       cmd="$*"
+       if ! $cmd ; then
+               FAIL "Command \`$cmd\` failed"
+       fi
+}
+
+DISPENSE="../dispense -H localhost -P ${PORT}"
+
+LD_LIBRARY_PATH=.. ../dispsrv -f ${BASEDIR}cfg_server.conf --dont-daemonise > ${BASEDIR}server.log 2>&1 &
+server_pid=$!
+
+cleanup() {
+       LOG "Killing ${server_pid}"
+       kill ${server_pid}
+}
+trap cleanup EXIT
+
+LOG "Server running on PID ${server_pid}"
+sleep 1
+echo "" | nc localhost ${PORT}

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