tests_jc2server.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #!/bin/bash
  2. # TravisCI Tests
  3. # Server Management Script
  4. # Author: Daniel Gibbs
  5. # Website: https://gameservermanagers.com
  6. version="101716"
  7. #### Advanced Variables ####
  8. # Github Branch Select
  9. # Allows for the use of different function files
  10. # from a different repo and/or branch.
  11. githubuser="dgibbs64"
  12. githubrepo="linuxgsm"
  13. githubbranch="$TRAVIS_BRANCH"
  14. ##### Script #####
  15. # Fetches core_dl for file downloads
  16. fn_fetch_core_dl(){
  17. github_file_url_dir="lgsm/functions"
  18. github_file_url_name="${functionfile}"
  19. filedir="${functionsdir}"
  20. filename="${github_file_url_name}"
  21. githuburl="https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/${github_file_url_dir}/${github_file_url_name}"
  22. # If the file is missing, then download
  23. if [ ! -f "${filedir}/${filename}" ]; then
  24. if [ ! -d "${filedir}" ]; then
  25. mkdir -p "${filedir}"
  26. fi
  27. echo -e " fetching ${filename}...\c"
  28. # Check curl exists and use available path
  29. curlpaths="$(command -v curl 2>/dev/null) $(which curl >/dev/null 2>&1) /usr/bin/curl /bin/curl /usr/sbin/curl /sbin/curl)"
  30. for curlcmd in ${curlpaths}
  31. do
  32. if [ -x "${curlcmd}" ]; then
  33. break
  34. fi
  35. done
  36. # If curl exists download file
  37. if [ "$(basename ${curlcmd})" == "curl" ]; then
  38. curlfetch=$(${curlcmd} -s --fail -o "${filedir}/${filename}" "${githuburl}" 2>&1)
  39. if [ $? -ne 0 ]; then
  40. echo -e "\e[0;31mFAIL\e[0m\n"
  41. echo "${curlfetch}"
  42. echo -e "${githuburl}\n"
  43. exit 1
  44. else
  45. echo -e "\e[0;32mOK\e[0m"
  46. fi
  47. else
  48. echo -e "\e[0;31mFAIL\e[0m\n"
  49. echo "Curl is not installed!"
  50. echo -e ""
  51. exit 1
  52. fi
  53. chmod +x "${filedir}/${filename}"
  54. fi
  55. source "${filedir}/${filename}"
  56. }
  57. core_dl.sh(){
  58. # Functions are defined in core_functions.sh.
  59. functionfile="${FUNCNAME}"
  60. fn_fetch_core_dl
  61. }
  62. core_functions.sh(){
  63. # Functions are defined in core_functions.sh.
  64. functionfile="${FUNCNAME}"
  65. fn_fetch_core_dl
  66. }
  67. core_dl.sh
  68. core_functions.sh
  69. # End of every test will expect the result to either pass or fail
  70. # If the script does not do as intended the whole test will fail
  71. # if excpecting a pass
  72. fn_test_result_pass(){
  73. if [ $? != 0 ]; then
  74. fn_print_fail "Test Failed"
  75. exitcode=1
  76. core_exit.sh
  77. else
  78. fn_print_ok "Test Passed"
  79. fi
  80. }
  81. # if excpecting a fail
  82. fn_test_result_fail(){
  83. if [ $? == 0 ]; then
  84. fn_print_fail "Test Failed"
  85. exitcode=1
  86. core_exit.sh
  87. else
  88. fn_print_ok "Test Passed"
  89. fi
  90. }
  91. echo "================================="
  92. echo "TravisCI Tests"
  93. echo "Linux Game Server Manager"
  94. echo "by Daniel Gibbs"
  95. echo "https://gameservermanagers.com"
  96. echo "================================="
  97. echo ""
  98. echo "================================="
  99. echo "Server Tests"
  100. echo "Using: ${gamename}"
  101. echo "Testing Branch: $TRAVIS_BRANCH"
  102. echo "================================="
  103. echo ""
  104. echo "0.0 - Preparing Enviroment"
  105. echo "================================="
  106. echo "Description:"
  107. echo "Preparing Enviroment to run tests"
  108. echo "Downloading jc2server"
  109. wget https://raw.githubusercontent.com/${githubuser}/${githubrepo}/${githubbranch}/JustCause2/jc2server
  110. chmod +x jc2server
  111. echo "Create log dir"
  112. mkdir -pv log/script/
  113. echo "Enable dev-debug"
  114. ./jc2server dev-debug
  115. echo "1.0 - start - no files"
  116. echo "================================="
  117. echo "Description:"
  118. echo "test script reaction to missing server files."
  119. echo ""
  120. ./jc2server start
  121. fn_test_result_fail
  122. echo ""
  123. echo "1.1 - getopt"
  124. echo "================================="
  125. echo "Description:"
  126. echo "displaying options messages."
  127. echo ""
  128. ./jc2server
  129. fn_test_result_pass
  130. echo ""
  131. echo "1.2 - getopt with incorrect args"
  132. echo "================================="
  133. echo "Description:"
  134. echo "displaying options messages."
  135. echo ""
  136. ./jc2server
  137. fn_test_result_fail
  138. echo "2.0 - install"
  139. echo "================================="
  140. echo "Description:"
  141. echo "install Just Cause 2 server."
  142. ./jc2server auto-install
  143. fn_test_result_pass