Bläddra i källkod

Merge pull request #528 from dgibbs64/travis-test

New Tests for Travis
Daniel Gibbs 10 år sedan
förälder
incheckning
e9f465bb6b
4 ändrade filer med 406 tillägg och 81 borttagningar
  1. 2 1
      .travis.yml
  2. 2 0
      functions/fn_start
  3. 44 80
      tests/tests_jc2server.sh
  4. 358 0
      tests/tests_ts3server.sh

+ 2 - 1
.travis.yml

@@ -22,4 +22,5 @@ addons:
 
 script:
 
-    - bash tests/test.sh
+    - bash tests/tests_jc2server.sh
+    - bash tests/tests_ts3server.sh

+ 2 - 0
functions/fn_start

@@ -63,6 +63,7 @@ if [ "${ts3status}" = "Server seems to have died" ] || [ "${ts3status}"	= "No se
 	fn_printfailnl "Unable to start ${servername}"
 	fn_scriptlog "Unable to start ${servername}"
 	echo -e "	Check log files: ${rootdir}/log"
+	exit 1
 else
 	fn_printok "${servername}"
 	fn_scriptlog "Started ${servername}"
@@ -188,6 +189,7 @@ if [ "${tmuxwc}" -eq 0 ]; then
 			fi
 		fi
 	fi
+exit 1	
 else
 	fn_printok "${servername}"
 	fn_scriptlog "Started ${servername}"

+ 44 - 80
tests/test.sh → tests/tests_jc2server.sh

@@ -1,9 +1,9 @@
 #!/bin/bash
-# Just Cause 2
+# TravisCI Tests
 # Server Management Script
 # Author: Daniel Gibbs
 # Website: http://gameservermanagers.com
-version="150715"
+version="071115"
 
 #### Variables ####
 
@@ -34,8 +34,7 @@ gamename="Just Cause 2"
 engine="avalanche"
 
 # Directories
-rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/jc2server"
-mkdir "${rootdir}"
+rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
 selfname="$(basename $0)"
 lockselfname=".${servicename}.lock"
 filesdir="${rootdir}/serverfiles"
@@ -88,28 +87,36 @@ fn_runfunction
 
 fn_functions
 
-getopt=$1
-
-fn_currentstatus(){
+fn_currentstatus_tmux(){
 pid=$(tmux list-sessions 2>&1 | awk '{print $1}' | grep -Ec "^${servicename}:")
-if [ "${pid}" == "0" ]; then
-	currentstatus="OFFLINE"
+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
-	
+	fn_currentstatus_tmux
 	echo""
 	echo "Required status: ${requiredstatus}"
 	counter=0
+	echo "Current status:  ${currentstatus}"
     while [  "${requiredstatus}" != "${currentstatus}" ]; do
     	counter=$((counter+1))
-    	fn_currentstatus
-	
-    	echo -ne "Current status:  ${currentstatus}\\r"
+    	fn_currentstatus_tmux
+		echo -ne "New status:  ${currentstatus}\\r"
+    	
 		if [ "${requiredstatus}" == "ONLINE" ]; then
 			(fn_start > /dev/null 2>&1)
 		else
@@ -120,10 +127,10 @@ fn_setstatus(){
     		echo "Current status:  ${currentstatus}"
     		echo ""
     		echo "Unable to start or stop server."
-    		exit
+    		exit 1
     	fi
     done
-    echo -ne "Current status:  ${currentstatus}\\r"
+    echo -ne "New status:  ${currentstatus}\\r"
     echo -e "\n"
     echo "Test starting:"
     echo ""
@@ -139,25 +146,35 @@ echo "================================="
 echo ""
 sleep 1
 echo "================================="
-echo "Generic Server Tests"
+echo "Server Tests"
 echo "Using: ${gamename}"
 echo "================================="
 echo ""
 sleep 1
-mkdir ${rootfdir}
+mkdir ${rootdir}
+
 
 
 echo "1.0 - start - no files"
 echo "================================="
 echo "Description:"
-echo "Test script reaction to missing server files."
-requiredstatus="OFFLINE"
-fn_setstatus
+echo "test script reaction to missing server files."
+echo ""
 (fn_start)
 echo ""
 echo "Test complete!"
 sleep 1
 echo ""
+echo "1.1 - getopt"
+echo "================================="
+echo "Description:"
+echo "displaying options messages."
+echo ""
+(fn_getopt)
+echo ""
+echo "Test complete!"
+sleep 1
+echo ""
 
 
 
@@ -165,8 +182,6 @@ echo "2.0 - install"
 echo "================================="
 echo "Description:"
 echo "install ${gamename} server."
-requiredstatus="OFFLINE"
-fn_setstatus
 fn_autoinstall
 echo ""
 echo "Test complete!"
@@ -201,7 +216,7 @@ echo "3.3 - start - updateonstart"
 echo "================================="
 echo "Description:"
 echo "will update server on start."
-requiredstatus="ONLINE"
+requiredstatus="OFFLINE"
 fn_setstatus
 (
 	updateonstart="on"
@@ -411,7 +426,7 @@ echo ""
 echo "6.0 - details"
 echo "================================="
 echo "Description:"
-echo "gsquery.py will fail to query port."
+echo "display details."
 requiredstatus="ONLINE"
 fn_setstatus
 fn_details
@@ -421,65 +436,14 @@ sleep 1
 echo ""
 
 echo "================================="
-echo "Generic Server Tests - Complete!"
+echo "Server Tests - Complete!"
 echo "Using: ${gamename}"
 echo "================================="
 echo ""
+requiredstatus="OFFLINE"
+fn_setstatus
 sleep 1
 fn_printinfo "Tidying up directories."
 sleep 1
-rm -rfv ${rootdir}
+rm -rfv ${serverfiles}
 echo "END"
-
-#!/bin/bash
-# Teamspeak 3
-# Server Management Script
-# Author: Daniel Gibbs
-# Website: http://gameservermanagers.com
-version="040715"
-
-#### Variables ####
-
-# Notification Email
-# (on|off)
-emailnotification="on"
-email="me@Danielgibbs.co.uk"
-
-# Start Variables
-updateonstart="off"
-
-# Server Details
-gamename="Teamspeak 3"
-servername="Teamspeak 3 Server"
-servicename="ts3-server"
-
-# Directories
-rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/ts3server"
-selfname="$(basename $0)"
-lockselfname=".${servicename}.lock"
-filesdir="${rootdir}/serverfiles"
-systemdir="${filesdir}"
-executabledir="${filesdir}"
-executable="./ts3server_startscript.sh"
-servercfg="${servicename}.ini"
-servercfgdir="${filesdir}"
-servercfgfullpath="${servercfgdir}/${servercfg}"
-backupdir="${rootdir}/backups"
-
-# Logging
-logdays="7"
-gamelogdir="${filesdir}/logs"
-scriptlogdir="${rootdir}/log/script"
-
-scriptlog="${scriptlogdir}/${servicename}-script.log"
-emaillog="${scriptlogdir}/${servicename}-email.log"
-
-scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S').log"
-
-
-echo "================================="
-echo "Generic Server Tests"
-echo "Using: ${gamename}"
-echo "================================="
-echo ""
-sleep 1

+ 358 - 0
tests/tests_ts3server.sh

@@ -0,0 +1,358 @@
+#!/bin/bash
+# TravisCI Tests
+# Server Management Script
+# Author: Daniel Gibbs
+# Website: http://gameservermanagers.com
+version="071115"
+
+#### Variables ####
+
+# Notification Email
+# (on|off)
+emailnotification="on"
+email="me@danielgibbs.co.uk"
+
+# Start Variables
+updateonstart="off"
+
+# Server Details
+gamename="Teamspeak 3"
+servername="Teamspeak 3 Server"
+servicename="ts3-server"
+
+# Directories
+rootdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+selfname="$(basename $0)"
+lockselfname=".${servicename}.lock"
+filesdir="${rootdir}/serverfiles"
+systemdir="${filesdir}"
+executabledir="${filesdir}"
+executable="./ts3server_startscript.sh"
+servercfg="${servicename}.ini"
+servercfgdir="${filesdir}"
+servercfgfullpath="${servercfgdir}/${servercfg}"
+backupdir="${rootdir}/backups"
+
+# Logging
+logdays="7"
+gamelogdir="${filesdir}/logs"
+scriptlogdir="${rootdir}/log/script"
+
+scriptlog="${scriptlogdir}/${servicename}-script.log"
+emaillog="${scriptlogdir}/${servicename}-email.log"
+
+scriptlogdate="${scriptlogdir}/${servicename}-script-$(date '+%d-%m-%Y-%H-%M-%S').log"
+
+##### Script #####
+# Do not edit
+
+fn_runfunction(){
+# Functions are downloaded and run with this function
+if [ ! -f "${rootdir}/functions/${functionfile}" ]; then
+	cd "${rootdir}"
+	if [ ! -d "functions" ]; then
+		mkdir functions
+	fi
+	cd functions
+	echo -e "    loading ${functionfile}...\c"
+	wget -N /dev/null https://raw.githubusercontent.com/dgibbs64/linuxgsm/master/functions/${functionfile} 2>&1 | grep -F HTTP | cut -c45-
+	chmod +x "${functionfile}"
+	cd "${rootdir}"
+fi
+source "${rootdir}/functions/${functionfile}"
+}
+
+fn_functions(){
+# Functions are defined in fn_functions.
+functionfile="${FUNCNAME}"
+fn_runfunction
+}
+
+fn_functions
+
+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_ts3
+	echo""
+	echo "Required status: ${requiredstatus}"
+	counter=0
+	echo "Current status:  ${currentstatus}"
+    while [  "${requiredstatus}" != "${currentstatus}" ]; do
+    	counter=$((counter+1))
+    	fn_currentstatus_ts3
+		echo -ne "New status:  ${currentstatus}\\r"
+    	
+		if [ "${requiredstatus}" == "ONLINE" ]; then
+			(fn_start)
+		else
+			(fn_stop)
+		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
+}
+
+echo "================================="
+echo "TravisCI Tests"
+echo "Linux Game Server Manager"
+echo "by Daniel Gibbs"
+echo "http://gameservermanagers.com"
+echo "================================="
+echo ""
+sleep 1
+echo "================================="
+echo "Server Tests"
+echo "Using: ${gamename}"
+echo "================================="
+echo ""
+sleep 1
+
+
+
+echo "1.0 - start - no files"
+echo "================================="
+echo "Description:"
+echo "test script reaction to missing server files."
+echo ""
+(fn_start)
+echo ""
+echo "Test complete!"
+sleep 1
+echo ""
+echo "1.1 - getopt"
+echo "================================="
+echo "Description:"
+echo "displaying options messages."
+echo ""
+(fn_getopt)
+echo ""
+echo "Test complete!"
+sleep 1
+echo ""
+
+
+
+echo "2.0 - install"
+echo "================================="
+echo "Description:"
+echo "install ${gamename} server."
+fn_autoinstall
+echo ""
+echo "Test complete!"
+sleep 1
+echo ""
+
+
+
+echo "3.1 - start"
+echo "================================="
+echo "Description:"
+echo "start ${gamename} server."
+requiredstatus="OFFLINE"
+fn_setstatus
+fn_start
+echo ""
+echo "Test complete!"
+sleep 1
+echo ""
+echo "3.2 - start - online"
+echo "================================="
+echo "Description:"
+echo "start ${gamename} server while already running."
+requiredstatus="ONLINE"
+fn_setstatus
+(fn_start)
+echo ""
+echo "Test complete!"
+sleep 1
+echo ""
+echo "3.3 - start - updateonstart"
+echo "================================="
+echo "Description:"
+echo "will update server on start."
+requiredstatus="OFFLINE"
+fn_setstatus
+(
+	updateonstart="on"
+	fn_start
+)
+echo ""
+echo "Test complete!"
+sleep 1
+echo ""
+echo "3.4 - stop"
+echo "================================="
+echo "Description:"
+echo "stop ${gamename} server."
+requiredstatus="ONLINE"
+fn_setstatus
+fn_stop
+echo ""
+echo "Test complete!"
+sleep 1
+echo ""
+echo "3.5 - stop - offline"
+echo "================================="
+echo "Description:"
+echo "stop ${gamename} server while already stopped."
+requiredstatus="OFFLINE"
+fn_setstatus
+(fn_stop)
+echo ""
+echo "Test complete!"
+sleep 1
+echo ""
+echo "3.6 - restart"
+echo "================================="
+echo "Description:"
+echo "restart ${gamename}."
+requiredstatus="ONLINE"
+fn_setstatus
+fn_restart
+echo ""
+echo "Test complete!"
+sleep 1
+echo ""
+echo "3.7 - restart - offline"
+echo "================================="
+echo "Description:"
+echo "restart ${gamename} while already stopped."
+requiredstatus="OFFLINE"
+fn_setstatus
+fn_restart
+echo ""
+echo "Test complete!"
+sleep 1
+echo ""
+
+
+
+echo "4.1 - update"
+echo "================================="
+echo "Description:"
+echo "check for updates."
+requiredstatus="OFFLINE"
+fn_setstatus
+fn_update_check
+echo ""
+echo "Test complete!"
+sleep 1
+echo ""
+echo "4.1 - update - old version"
+echo "================================="
+echo "Description:"
+echo "change the version number tricking LGSM to update."
+requiredstatus="OFFLINE"
+sed -i 's/[0-9]\+/0/g' ${gamelogdir}/ts3server*_0.log
+fn_setstatus
+fn_update_check
+echo ""
+echo "Test complete!"
+sleep 1
+echo ""
+
+echo "5.1 - monitor - online"
+echo "================================="
+echo "Description:"
+echo "run monitor server while already running."
+requiredstatus="ONLINE"
+fn_setstatus
+(fn_monitor)
+echo ""
+echo "Test complete!"
+sleep 1
+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
+(fn_monitor)
+echo ""
+echo "Test complete!"
+sleep 1
+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_printinfonl "creating lockfile."
+date > "${rootdir}/${lockselfname}"
+(fn_monitor)
+echo ""
+echo "Test complete!"
+sleep 1
+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}"
+(fn_monitor)
+echo ""
+fn_printinfonl "Reseting ${servercfg}."
+fn_install_config
+echo ""
+echo "Test complete!"
+sleep 1
+echo ""
+
+
+
+echo "6.0 - details"
+echo "================================="
+echo "Description:"
+echo "display details."
+requiredstatus="ONLINE"
+fn_setstatus
+fn_details
+echo ""
+echo "Test complete!"
+sleep 1
+echo ""
+
+echo "================================="
+echo "Server Tests - Complete!"
+echo "Using: ${gamename}"
+echo "================================="
+echo ""
+requiredstatus="OFFLINE"
+fn_setstatus
+sleep 1
+fn_printinfo "Tidying up directories."
+sleep 1
+rm -rfv ${serverfiles}
+echo "END"