Browse Source

Fully working test (hopefully)

pull/914/head
Daniel Gibbs 9 years ago
parent
commit
da0c287314
  1. 223
      tests/tests_jc2server.sh

223
tests/tests_jc2server.sh

@ -5,6 +5,38 @@
# Website: https://gameservermanagers.com # Website: https://gameservermanagers.com
version="101716" version="101716"
if [ -f ".dev-debug" ]; then
exec 5>dev-debug.log
BASH_XTRACEFD="5"
set -x
fi
#### Variables ####
# Notification Alerts
# (on|off)
# Email
emailalert="off"
email="[email protected]"
# Pushbullet
# https://www.pushbullet.com/#settings
pushbulletalert="off"
pushbullettoken="accesstoken"
# Steam login
steamuser="anonymous"
steampass=""
# Start Variables
updateonstart="off"
fn_parms(){
parms=""
}
#### Advanced Variables #### #### Advanced Variables ####
# Github Branch Select # Github Branch Select
@ -13,11 +45,15 @@ version="101716"
githubuser="dgibbs64" githubuser="dgibbs64"
githubrepo="linuxgsm" githubrepo="linuxgsm"
githubbranch="$TRAVIS_BRANCH" githubbranch="$TRAVIS_BRANCH"
githubbranch="exitcodes"
# Steam # Steam
appid="261140" appid="261140"
##### Script ##### # Server Details
servicename="jc2-server"
gamename="Just Cause 2"
engine="avalanche"
# Directories # Directories
rootdir="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))" rootdir="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))"
@ -36,10 +72,22 @@ servercfgfullpath="${servercfgdir}/${servercfg}"
servercfgdefault="${servercfgdir}/default_config.lua" servercfgdefault="${servercfgdir}/default_config.lua"
backupdir="${rootdir}/backups" backupdir="${rootdir}/backups"
# Server Details # Logging
servicename="jc2-server" logdays="7"
gamename="Just Cause 2" #gamelogdir="" # No server logs available
engine="avalanche" scriptlogdir="${rootdir}/log/script"
consolelogdir="${rootdir}/log/console"
consolelogging="on"
scriptlog="${scriptlogdir}/${servicename}-script.log"
consolelog="${consolelogdir}/${servicename}-console.log"
emaillog="${scriptlogdir}/${servicename}-email.log"
scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S').log"
consolelogdate="${consolelogdir}/${servicename}-console-$(date '+%d-%m-%Y-%H-%M-%S').log"
##### Script #####
# Do not edit
# Fetches core_dl for file downloads # Fetches core_dl for file downloads
fn_fetch_core_dl(){ fn_fetch_core_dl(){
@ -130,9 +178,9 @@ fn_setstatus(){
echo -ne "New status: ${currentstatus}\\r" echo -ne "New status: ${currentstatus}\\r"
if [ "${requiredstatus}" == "ONLINE" ]; then if [ "${requiredstatus}" == "ONLINE" ]; then
./jc2server start > /dev/null 2>&1 (command_start.sh > /dev/null 2>&1)
else else
./jc2server stop > /dev/null 2>&1 (command_stop.sh > /dev/null 2>&1)
fi fi
if [ "${counter}" -gt "5" ]; then if [ "${counter}" -gt "5" ]; then
currentstatus="FAIL" currentstatus="FAIL"
@ -154,11 +202,17 @@ fn_setstatus(){
# if excpecting a pass # if excpecting a pass
fn_test_result_pass(){ fn_test_result_pass(){
if [ $? != 0 ]; then if [ $? != 0 ]; then
fn_print_fail_nl "Test Failed" echo "================================="
echo "Expected result: PASS"
echo "Actual result: FAIL"
fn_print_fail_nl "TEST FAILED"
exitcode=1 exitcode=1
core_exit.sh core_exit.sh
else else
fn_print_ok_nl "Test Passed" echo "================================="
echo "Expected result: PASS"
echo "Actual result: PASS"
fn_print_ok_nl "TEST PASSED"
echo "" echo ""
fi fi
} }
@ -166,11 +220,17 @@ fn_test_result_pass(){
# if excpecting a fail # if excpecting a fail
fn_test_result_fail(){ fn_test_result_fail(){
if [ $? == 0 ]; then if [ $? == 0 ]; then
fn_print_fail_nl "Test Failed" echo "================================="
echo "Expected result: FAIL"
echo "Actual result: PASS"
fn_print_fail_nl "TEST FAILED"
exitcode=1 exitcode=1
core_exit.sh core_exit.sh
else else
fn_print_ok_nl "Test Passed" echo "================================="
echo "Expected result: FAIL"
echo "Actual result: FAIL"
fn_print_ok_nl "TEST PASSED"
echo "" echo ""
fi fi
} }
@ -189,38 +249,33 @@ echo "Testing Branch: $TRAVIS_BRANCH"
echo "=================================" echo "================================="
echo "" echo ""
echo "0.0 - Preparing Enviroment" echo "0.0 - Enable dev-debug"
echo "=================================" echo "================================="
echo "Description:" echo "Description:"
echo "Preparing Enviroment to run tests" echo "Preparing Enviroment to run tests"
echo ""
echo "Downloading jc2server"
wget https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/JustCause2/jc2server
chmod +x jc2server
echo "Create log dir"
mkdir -pv log/script/
echo "Make functions executable"
chmod +x lgsm/functions/*
echo "Enable dev-debug" echo "Enable dev-debug"
./jc2server dev-debug (command_dev_debug.sh)
fn_test_result_pass
echo "1.0 - start - no files" echo "1.0 - start - no files"
echo "=================================" echo "================================="
echo "Description:" echo "Description:"
echo "test script reaction to missing server files." echo "test script reaction to missing server files."
echo ""
echo "Command: ./jc2server start" echo "Command: ./jc2server start"
./jc2server start echo ""
(command_start.sh)
fn_test_result_fail fn_test_result_fail
echo "" echo ""
echo "1.1 - getopt" echo "1.1 - getopt"
echo "=================================" echo "================================="
echo "Description:" echo "Description:"
echo "displaying options messages." echo "displaying options messages."
echo ""
echo "Command: ./jc2server" echo "Command: ./jc2server"
./jc2server echo ""
(core_getopt.sh)
fn_test_result_pass fn_test_result_pass
echo "" echo ""
@ -228,25 +283,21 @@ echo "1.2 - getopt with incorrect args"
echo "=================================" echo "================================="
echo "Description:" echo "Description:"
echo "displaying options messages." echo "displaying options messages."
echo ""
echo "Command: ./jc2server abc123" echo "Command: ./jc2server abc123"
./jc2server abc123 echo ""
getopt="abc123"
(core_getopt.sh)
fn_test_result_fail fn_test_result_fail
echo "" echo ""
echo "2.0 - install" echo "2.0 - install"
echo "=================================" echo "================================="
echo "Description:" echo "Description:"
echo "install Just Cause 2 server." echo "install ${gamename} server."
echo "Command: ./jc2server abc123" echo "Command: ./jc2server auto-install"
./jc2server auto-install (fn_autoinstall)
fn_test_result_pass fn_test_result_pass
echo "================================="
ls -al
echo "================================="
ls -al "${filesdir}"
echo "================================="
echo "" echo ""
echo "3.1 - start" echo "3.1 - start"
@ -255,7 +306,8 @@ echo "Description:"
echo "start ${gamename} server." echo "start ${gamename} server."
echo "Command: ./jc2server start" echo "Command: ./jc2server start"
requiredstatus="OFFLINE" requiredstatus="OFFLINE"
./jc2server start fn_setstatus
(command_start.sh)
fn_test_result_pass fn_test_result_pass
echo "" echo ""
@ -265,27 +317,40 @@ echo "Description:"
echo "start ${gamename} server while already running." echo "start ${gamename} server while already running."
echo "Command: ./jc2server start" echo "Command: ./jc2server start"
requiredstatus="ONLINE" requiredstatus="ONLINE"
./jc2server start fn_setstatus
(command_start.sh)
fn_test_result_fail fn_test_result_fail
echo "" echo ""
echo "3.3 - stop" echo "3.3 - start - updateonstart"
echo "================================="
echo "Description:"
echo "will update server on start."
echo "Command: ./jc2server start"
requiredstatus="OFFLINE"
fn_setstatus
(updateonstart="on";command_start.sh)
fn_test_result_pass
echo ""
echo "3.4 - stop"
echo "=================================" echo "================================="
echo "Description:" echo "Description:"
echo "stop ${gamename} server." echo "stop ${gamename} server."
echo "Command: ./jc2server stop" echo "Command: ./jc2server stop"
requiredstatus="ONLINE" requiredstatus="ONLINE"
./jc2server stop fn_setstatus
(command_stop.sh)
fn_test_result_pass fn_test_result_pass
echo "" echo ""
echo "3.4 - stop - offline" echo "3.5 - stop - offline"
echo "=================================" echo "================================="
echo "Description:" echo "Description:"
echo "stop ${gamename} server while already stopped." echo "stop ${gamename} server while already stopped."
echo "Command: ./jc2server stop" echo "Command: ./jc2server stop"
requiredstatus="OFFLINE" requiredstatus="OFFLINE"
./jc2server stop (command_stop.sh)
fn_test_result_fail fn_test_result_fail
echo "" echo ""
@ -295,7 +360,19 @@ echo "Description:"
echo "restart ${gamename}." echo "restart ${gamename}."
echo "Command: ./jc2server restart" echo "Command: ./jc2server restart"
requiredstatus="ONLINE" requiredstatus="ONLINE"
./jc2server restart fn_setstatus
command_restart.sh
fn_test_result_pass
echo ""
echo "3.7 - restart - offline"
echo "================================="
echo "Description:"
echo "restart ${gamename} while already stopped."
echo "Command: ./jc2server restart"
requiredstatus="OFFLINE"
fn_setstatus
command_restart.sh
fn_test_result_pass fn_test_result_pass
echo "4.1 - update" echo "4.1 - update"
@ -304,7 +381,8 @@ echo "Description:"
echo "check for updates." echo "check for updates."
echo "Command: ./jc2server update" echo "Command: ./jc2server update"
requiredstatus="OFFLINE" requiredstatus="OFFLINE"
./jc2server update fn_setstatus
(command_update.sh)
fn_test_result_pass fn_test_result_pass
echo "" echo ""
@ -314,9 +392,10 @@ echo "Description:"
echo "change the buildid tricking SteamCMD to update." echo "change the buildid tricking SteamCMD to update."
echo "Command: ./jc2server update" echo "Command: ./jc2server update"
requiredstatus="OFFLINE" requiredstatus="OFFLINE"
fn_setstatus
fn_print_info_nl "changed buildid to 0." fn_print_info_nl "changed buildid to 0."
sed -i 's/[0-9]\+/0/' "${filesdir}/steamapps/appmanifest_${appid}.acf" sed -i 's/[0-9]\+/0/' "${filesdir}/steamapps/appmanifest_${appid}.acf"
./jc2server update (command_update.sh)
fn_test_result_pass fn_test_result_pass
echo "" echo ""
@ -326,9 +405,10 @@ echo "Description:"
echo "change the buildid tricking SteamCMD to update server while already running." echo "change the buildid tricking SteamCMD to update server while already running."
echo "Command: ./jc2server update" echo "Command: ./jc2server update"
requiredstatus="ONLINE" requiredstatus="ONLINE"
fn_setstatus
fn_print_info_nl "changed buildid to 0." fn_print_info_nl "changed buildid to 0."
sed -i 's/[0-9]\+/0/' "${filesdir}/steamapps/appmanifest_${appid}.acf" sed -i 's/[0-9]\+/0/' "${filesdir}/steamapps/appmanifest_${appid}.acf"
./jc2server update (command_update.sh)
fn_test_result_pass fn_test_result_pass
echo "" echo ""
@ -338,9 +418,10 @@ echo "Description:"
echo "removing appmanifest file will cause script to repair." echo "removing appmanifest file will cause script to repair."
echo "Command: ./jc2server update" echo "Command: ./jc2server update"
requiredstatus="OFFLINE" requiredstatus="OFFLINE"
fn_setstatus
fn_print_info_nl "removed appmanifest_${appid}.acf." fn_print_info_nl "removed appmanifest_${appid}.acf."
rm --verbose "${filesdir}/steamapps/appmanifest_${appid}.acf" rm --verbose "${filesdir}/steamapps/appmanifest_${appid}.acf"
./jc2server update (command_update.sh)
fn_test_result_pass fn_test_result_pass
echo "" echo ""
@ -350,7 +431,19 @@ echo "Description:"
echo "force-update bypassing update check." echo "force-update bypassing update check."
echo "Command: ./jc2server force-update" echo "Command: ./jc2server force-update"
requiredstatus="OFFLINE" requiredstatus="OFFLINE"
./jc2server force-update fn_setstatus
(forceupdate=1;command_update.sh)
fn_test_result_pass
echo ""
echo "4.6 - force-update - online"
echo "================================="
echo "Description:"
echo "force-update bypassing update check server while already running."
echo "Command: ./jc2server force-update"
requiredstatus="ONLINE"
fn_setstatus
(forceupdate=1;command_update.sh)
fn_test_result_pass fn_test_result_pass
echo "" echo ""
@ -360,7 +453,8 @@ echo "Description:"
echo "validate server files." echo "validate server files."
echo "Command: ./jc2server validate" echo "Command: ./jc2server validate"
requiredstatus="OFFLINE" requiredstatus="OFFLINE"
./jc2server validate fn_setstatus
(command_validate.sh)
fn_test_result_pass fn_test_result_pass
echo "" echo ""
@ -368,9 +462,11 @@ echo "4.8 - validate - online"
echo "=================================" echo "================================="
echo "Description:" echo "Description:"
echo "validate server files while server while already running." echo "validate server files while server while already running."
echo ""
echo "Command: ./jc2server validate" echo "Command: ./jc2server validate"
requiredstatus="ONLINE" requiredstatus="ONLINE"
./jc2server validate fn_setstatus
(command_validate.sh)
fn_test_result_pass fn_test_result_pass
echo "" echo ""
@ -380,9 +476,11 @@ echo "Description:"
echo "run monitor server while already running." echo "run monitor server while already running."
echo "Command: ./jc2server monitor" echo "Command: ./jc2server monitor"
requiredstatus="ONLINE" requiredstatus="ONLINE"
./jc2server monitor fn_setstatus
(command_monitor.sh)
fn_test_result_pass fn_test_result_pass
echo "" echo ""
echo "5.2 - monitor - offline - with lockfile" echo "5.2 - monitor - offline - with lockfile"
echo "=================================" echo "================================="
@ -390,11 +488,13 @@ echo "Description:"
echo "run monitor while server is offline with lockfile." echo "run monitor while server is offline with lockfile."
echo "Command: ./jc2server monitor" echo "Command: ./jc2server monitor"
requiredstatus="OFFLINE" requiredstatus="OFFLINE"
fn_setstatus
fn_print_info_nl "creating lockfile." fn_print_info_nl "creating lockfile."
date > "${rootdir}/${lockselfname}" date > "${rootdir}/${lockselfname}"
./jc2server monitor (command_monitor.sh)
fn_test_result_fail fn_test_result_fail
echo "" echo ""
echo "5.3 - monitor - offline - no lockfile" echo "5.3 - monitor - offline - no lockfile"
echo "=================================" echo "================================="
@ -402,7 +502,8 @@ echo "Description:"
echo "run monitor while server is offline with no lockfile." echo "run monitor while server is offline with no lockfile."
echo "Command: ./jc2server monitor" echo "Command: ./jc2server monitor"
requiredstatus="OFFLINE" requiredstatus="OFFLINE"
./jc2server monitor fn_setstatus
(command_monitor.sh)
fn_test_result_fail fn_test_result_fail
echo "" echo ""
@ -412,12 +513,14 @@ echo "Description:"
echo "gsquery.py will fail to query port." echo "gsquery.py will fail to query port."
echo "Command: ./jc2server monitor" echo "Command: ./jc2server monitor"
requiredstatus="ONLINE" requiredstatus="ONLINE"
fn_setstatus
sed -i 's/[0-9]\+/0/' "${servercfgfullpath}" sed -i 's/[0-9]\+/0/' "${servercfgfullpath}"
./jc2server monitor (command_monitor.sh)
fn_test_result_fail fn_test_result_fail
echo "" echo ""
fn_print_info_nl "Reseting ${servercfg}." fn_print_info_nl "Reseting ${servercfg}."
wget -p "${servercfgfullpath}" https://raw.githubusercontent.com/dgibbs64/linuxgsm/master/JustCause2/cfg/config.lua install_config.sh
fn_test_result_fail
echo "" echo ""
echo "6.0 - details" echo "6.0 - details"
@ -426,7 +529,8 @@ echo "Description:"
echo "display details." echo "display details."
echo "Command: ./jc2server details" echo "Command: ./jc2server details"
requiredstatus="ONLINE" requiredstatus="ONLINE"
./jc2server details fn_setstatus
command_details.sh
fn_test_result_pass fn_test_result_pass
echo "" echo ""
@ -434,5 +538,10 @@ echo "================================="
echo "Server Tests - Complete!" echo "Server Tests - Complete!"
echo "Using: ${gamename}" echo "Using: ${gamename}"
echo "=================================" echo "================================="
echo "" requiredstatus="OFFLINE"
requiredstatus="OFFLINE" fn_setstatus
sleep 1
fn_print_info "Tidying up directories."
sleep 1
rm -rfv "${serverfiles}"
core_exit.sh

Loading…
Cancel
Save