From 19059b84863d26315fcb6cd04f2ae2b3422e8b22 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Sun, 10 Jul 2016 19:12:18 +0100 Subject: [PATCH] Starting tests from scratch --- tests/tests_jc2server.sh | 450 +-------------------------------------- 1 file changed, 8 insertions(+), 442 deletions(-) diff --git a/tests/tests_jc2server.sh b/tests/tests_jc2server.sh index 4f5605f7b..16238087e 100644 --- a/tests/tests_jc2server.sh +++ b/tests/tests_jc2server.sh @@ -5,31 +5,6 @@ # Website: https://gameservermanagers.com version="101716" -#### Variables #### - -# Notification Alerts -# (on|off) - -# Email -emailalert="off" -email="email@example.com" - -# Pushbullet -# https://www.pushbullet.com/#settings -pushbulletalert="off" -pushbullettoken="accesstoken" - -# Steam login -steamuser="anonymous" -steampass="" - -# Start Variables -updateonstart="off" - -fn_parms(){ -parms="" -} - #### Advanced Variables #### # Github Branch Select @@ -39,155 +14,8 @@ githubuser="dgibbs64" githubrepo="linuxgsm" githubbranch="$TRAVIS_BRANCH" -# Steam -appid="261140" - -# Server Details -servicename="jc2-server" -gamename="Just Cause 2" -engine="avalanche" - -# Directories -rootdir="$(dirname $(readlink -f "${BASH_SOURCE[0]}"))" -selfname="$(basename $(readlink -f "${BASH_SOURCE[0]}"))" -lockselfname=".${servicename}.lock" -lgsmdir="${rootdir}/lgsm" -functionsdir="${lgsmdir}/functions" -libdir="${lgsmdir}/lib" -filesdir="${rootdir}/serverfiles" -systemdir="${filesdir}" -executabledir="${filesdir}" -executable="./Jcmp-Server" -servercfg="config.lua" -servercfgdir="${filesdir}" -servercfgfullpath="${servercfgdir}/${servercfg}" -servercfgdefault="${servercfgdir}/default_config.lua" -backupdir="${rootdir}/backups" - -# Logging -logdays="7" -#gamelogdir="" # No server logs available -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 -fn_fetch_core_dl(){ -github_file_url_dir="lgsm/functions" -github_file_url_name="${functionfile}" -filedir="${functionsdir}" -filename="${github_file_url_name}" -githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}" -# If the file is missing, then download -if [ ! -f "${filedir}/${filename}" ]; then - if [ ! -d "${filedir}" ]; then - mkdir -p "${filedir}" - fi - echo -e " fetching ${filename}...\c" - # Check curl exists and use available path - curlpaths="$(command -v curl 2>/dev/null) $(which curl >/dev/null 2>&1) /usr/bin/curl /bin/curl /usr/sbin/curl /sbin/curl)" - for curlcmd in ${curlpaths} - do - if [ -x "${curlcmd}" ]; then - break - fi - done - # If curl exists download file - if [ "$(basename ${curlcmd})" == "curl" ]; then - curlfetch=$(${curlcmd} -s --fail -o "${filedir}/${filename}" "${githuburl}" 2>&1) - if [ $? -ne 0 ]; then - echo -e "\e[0;31mFAIL\e[0m\n" - echo "${curlfetch}" - echo -e "${githuburl}\n" - exit 1 - else - echo -e "\e[0;32mOK\e[0m" - fi - else - echo -e "\e[0;31mFAIL\e[0m\n" - echo "Curl is not installed!" - echo -e "" - exit 1 - fi - chmod +x "${filedir}/${filename}" -fi -source "${filedir}/${filename}" -} - -core_dl.sh(){ -# Functions are defined in core_functions.sh. -functionfile="${FUNCNAME}" -fn_fetch_core_dl -} - -core_functions.sh(){ -# Functions are defined in core_functions.sh. -functionfile="${FUNCNAME}" -fn_fetch_core_dl -} -core_dl.sh -core_functions.sh - -fn_currentstatus_tmux(){ -pid=$(tmux list-sessions 2>&1 | awk '{print $1}' | grep -Ec "^${servicename}:") -if [ "${pid}" != "0" ]; then - currentstatus="ONLINE" -else - currentstatus="OFFLINE" -fi -} - -fn_currentstatus_ts3(){ -ts3status=$(${executable} status servercfgfullpathfile=${servercfgfullpath}) - -if [ "${ts3status}" == "Server is running" ]; then - currentstatus="ONLINE" -else - currentstatus="OFFLINE" -fi -} - -fn_setstatus(){ - fn_currentstatus_tmux - echo"" - echo "Required status: ${requiredstatus}" - counter=0 - echo "Current status: ${currentstatus}" - while [ "${requiredstatus}" != "${currentstatus}" ]; do - counter=$((counter+1)) - fn_currentstatus_tmux - echo -ne "New status: ${currentstatus}\\r" - - if [ "${requiredstatus}" == "ONLINE" ]; then - (command_start.sh > /dev/null 2>&1) - else - (command_stop.sh > /dev/null 2>&1) - fi - if [ "${counter}" -gt "5" ]; then - currentstatus="FAIL" - echo "Current status: ${currentstatus}" - echo "" - echo "Unable to start or stop server." - exit 1 - fi - done - echo -ne "New status: ${currentstatus}\\r" - echo -e "\n" - echo "Test starting:" - echo "" - sleep 0.5 -} +wget https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/JustCause2/jc2server echo "=================================" echo "TravisCI Tests" @@ -202,276 +30,14 @@ echo "Using: ${gamename}" echo "Testing Branch: $TRAVIS_BRANCH" echo "=================================" echo "" -mkdir "${rootdir}" - -echo "0.0 - Enable Dev-Debug" -echo "=================================" -echo "Description:" -echo "Enabling dev-debug to display exit codes" -(command_dev_debug.sh) - -echo "1.0 - start - no files" -echo "=================================" -echo "Description:" -echo "test script reaction to missing server files." -echo "" -(command_start.sh) -if [ $? == 0 ]; then - fn_print_fail "Test Failure" - exitcode=1 - core_exit.sh -else - fn_print_ok "Test Pass" -fi -echo "" -echo "1.1 - getopt" -echo "=================================" -echo "Description:" -echo "displaying options messages." -echo "" -(core_getopt.sh) -echo "" -echo "Test complete!" -echo "" - -echo "2.0 - install" -echo "=================================" -echo "Description:" -echo "install ${gamename} server." -fn_autoinstall -echo "" -echo "Test complete!" -echo "" - -echo "3.1 - start" -echo "=================================" -echo "Description:" -echo "start ${gamename} server." -requiredstatus="OFFLINE" -fn_setstatus -command_start.sh -echo "" -echo "Test complete!" -echo "" -echo "3.2 - start - online" -echo "=================================" -echo "Description:" -echo "start ${gamename} server while already running." -requiredstatus="ONLINE" -fn_setstatus -(command_start.sh) -echo "" -echo "Test complete!" -echo "" -echo "3.3 - start - updateonstart" -echo "=================================" -echo "Description:" -echo "will update server on start." -requiredstatus="OFFLINE" -fn_setstatus -( - updateonstart="on" - command_start.sh -) -echo "" -echo "Test complete!" - -echo "" -echo "3.4 - stop" -echo "=================================" -echo "Description:" -echo "stop ${gamename} server." -requiredstatus="ONLINE" -fn_setstatus -command_stop.sh -echo "" -echo "Test complete!" -echo "" -echo "3.5 - stop - offline" -echo "=================================" -echo "Description:" -echo "stop ${gamename} server while already stopped." -requiredstatus="OFFLINE" -fn_setstatus -(command_stop.sh) -echo "" -echo "Test complete!" -echo "" -echo "3.6 - restart" -echo "=================================" -echo "Description:" -echo "restart ${gamename}." -requiredstatus="ONLINE" -fn_setstatus -command_restart.sh -echo "" -echo "Test complete!" -echo "" -echo "3.7 - restart - offline" -echo "=================================" -echo "Description:" -echo "restart ${gamename} while already stopped." -requiredstatus="OFFLINE" -fn_setstatus -command_restart.sh -echo "" -echo "Test complete!" -echo "" - -echo "4.1 - update" -echo "=================================" -echo "Description:" -echo "check for updates." -requiredstatus="OFFLINE" -fn_setstatus -update_check.sh -echo "" -echo "Test complete!" -echo "" -echo "4.2 - update - change buildid" -echo "=================================" -echo "Description:" -echo "change the buildid tricking SteamCMD to update." -requiredstatus="OFFLINE" -fn_setstatus -fn_print_info_nl "changed buildid to 0." -sed -i 's/[0-9]\+/0/' ${filesdir}/steamapps/appmanifest_${appid}.acf -update_check.sh -echo "" -echo "Test complete!" -echo "" -echo "4.3 - update - change buildid - online" -echo "=================================" -echo "Description:" -echo "change the buildid tricking SteamCMD to update server while already running." -requiredstatus="ONLINE" -fn_setstatus -fn_print_info_nl "changed buildid to 0." -sed -i 's/[0-9]\+/0/' ${filesdir}/steamapps/appmanifest_${appid}.acf -update_check.sh -echo "" -echo "Test complete!" -echo "" -echo "4.4 - update - remove appmanifest file" -echo "=================================" -echo "Description:" -echo "removing appmanifest file will cause script to repair." -requiredstatus="OFFLINE" -fn_setstatus -fn_print_info_nl "removed appmanifest_${appid}.acf." -rm --verbose "${filesdir}/steamapps/appmanifest_${appid}.acf" -update_check.sh -echo "" -echo "Test complete!" -echo "" -echo "4.5 - force-update" -echo "=================================" -echo "Description:" -echo "force-update bypassing update check." -requiredstatus="OFFLINE" -fn_setstatus -update_check.sh -echo "" -echo "Test complete!" -echo "" -echo "4.6 - force-update - online" -echo "=================================" -echo "Description:" -echo "force-update bypassing update check server while already running." -requiredstatus="ONLINE" -fn_setstatus -update_check.sh -echo "" -echo "Test complete!" -echo "" -echo "4.7 - validate" -echo "=================================" -echo "Description:" -echo "validate server files." -requiredstatus="OFFLINE" -fn_setstatus -command_validate.sh -echo "" -echo "Test complete!" -echo "" -echo "4.8 - validate - online" -echo "=================================" -echo "Description:" -echo "validate server files while server while already running." -requiredstatus="ONLINE" -fn_setstatus -command_validate.sh -echo "" -echo "Test complete!" -echo "" - -echo "5.1 - monitor - online" -echo "=================================" -echo "Description:" -echo "run monitor server while already running." -requiredstatus="ONLINE" -fn_setstatus -(command_monitor.sh) -echo "" -echo "Test complete!" -echo "" -echo "5.2 - monitor - offline - no lockfile" -echo "=================================" -echo "Description:" -echo "run monitor while server is offline with no lockfile." -requiredstatus="OFFLINE" -fn_setstatus -(command_monitor.sh) -echo "" -echo "Test complete!" -echo "" -echo "5.3 - monitor - offline - with lockfile" -echo "=================================" -echo "Description:" -echo "run monitor while server is offline with no lockfile." -requiredstatus="OFFLINE" -fn_setstatus -fn_print_info_nl "creating lockfile." -date > "${rootdir}/${lockselfname}" -(command_monitor.sh) -echo "" -echo "Test complete!" -echo "" -echo "5.4 - monitor - gsquery.py failure" -echo "=================================" -echo "Description:" -echo "gsquery.py will fail to query port." -requiredstatus="ONLINE" -fn_setstatus -sed -i 's/[0-9]\+/0/' "${servercfgfullpath}" -(command_monitor.sh) -echo "" -fn_print_info_nl "Reseting ${servercfg}." -install_config.sh -echo "" -echo "Test complete!" -echo "" -echo "6.0 - details" +echo "0.0 - Preparing Enviroment" echo "=================================" echo "Description:" -echo "display details." -requiredstatus="ONLINE" -fn_setstatus -command_details.sh -echo "" -echo "Test complete!" -echo "" -echo "=================================" -echo "Server Tests - Complete!" -echo "Using: ${gamename}" -echo "=================================" -echo "" -requiredstatus="OFFLINE" -fn_setstatus - -fn_print_info "Tidying up directories." - -rm -rfv ${serverfiles} -echo "END" +echo "Preparing Enviroment to run tests" +echo "Downloading jc2server" +wget https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/JustCause2/jc2server +chmod +x +echo "Enable dev-debug" +./jc2server dev-debug \ No newline at end of file