Browse Source

feat(testing): add code coverage and streamline unit testing (#2620)

pull/2628/head
Daniel Gibbs 5 years ago
committed by GitHub
parent
commit
75c3238377
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 57
      .travis.yml
  2. 2
      README.md
  3. 4
      lgsm/functions/command_fastdl.sh
  4. 26
      tests/tests_fctrserver.sh
  5. 8
      tests/tests_jc2server.sh
  6. 14
      tests/tests_kcov.sh
  7. 8
      tests/tests_mcserver.sh
  8. 8
      tests/tests_ts3server.sh

57
.travis.yml

@ -1,49 +1,44 @@
language: node_js language: node_js
dist: bionic dist: bionic
node_js: node_js:
- 10 - "stable"
env:
global:
secure: VsS98cwJ5X/Ev3HEm7KEOPftYay+7jNTHepTS7d+gQNHcDR1UYKTmqlQNSIoUC52Ejs1cHq43jOfle4330zDPOYI0v5BMri6/iZKpmMxAw6KWNiUgSkziTP2kHC4NRLwEoU2WQTI3JZQjrBEfsPmD81+yR/eWXV3rph+YcSOxao=
before_script: before_script:
- curl -L "https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/shunit2/shunit2-2.1.6.tgz" | tar zx - curl -L "https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/shunit2/shunit2-2.1.6.tgz" | tar zx
install: install:
npm install gamedig - npm install gamedig
addons: addons:
apt: apt:
packages: packages:
- mailutils - mailutils
- postfix - postfix
- curl
- wget
- file
- bzip2
- gzip
- unzip
- bsdmainutils
- python3
- util-linux
- ca-certificates
- binutils
- bc
- jq - jq
- tmux
- lib32gcc1 - lib32gcc1
- libstdc++6
- libstdc++6:i386 - libstdc++6:i386
- net-tools
- iproute2
- shellcheck - shellcheck
- libcurl4-openssl-dev
- libdw-dev
- cmake
jobs: jobs:
include: include:
- stage: jobs - stage: "Jobs"
script: bash tests/tests_jc2server.sh name: "code coverage"
- # stage name not required script: bash tests/tests_kcov.sh; kcov --bash-method=DEBUG coverage tests/tests_mcserver.sh
script: bash tests/tests_fctrserver.sh - script: bash tests/tests_mcserver.sh
- # stage name not required name: "Minecraft"
script: bash tests/tests_mcserver.sh - script: bash tests/tests_jc2server.sh
- # stage name not required name: "Just Cause 2"
script: bash tests/tests_ts3server.sh - script: bash tests/tests_fctrserver.sh
- # stage name not required name: "Factorio"
script: bash tests/tests_defaultcfg/tests_defaultcfg.sh - script: bash tests/tests_ts3server.sh
- # retired as codacy does this check. name: "Teamspeak 3"
# script: bash tests/tests_shellcheck.sh - script: bash tests/tests_defaultcfg/tests_defaultcfg.sh
name: "_default.cfg checks"
after_success:
- bash <(curl -Ls https://coverage.codacy.com/get.sh)

2
README.md

File diff suppressed because one or more lines are too long

4
lgsm/functions/command_fastdl.sh

@ -194,7 +194,7 @@ fn_fastdl_preview(){
tput rc; tput el tput rc; tput el
echo -e "gathering ${directory} ${allowed_extention} : ${fileswc}..." echo -e "gathering ${directory} ${allowed_extention} : ${fileswc}..."
echo -e "${ext}" >> "${tmpdir}/fastdl_files_to_compress.txt" echo -e "${ext}" >> "${tmpdir}/fastdl_files_to_compress.txt"
done < <(find "${systemdir}/${directory}" -type f -iname ${allowed_extention}) done < <(find "${systemdir}/${directory}" -type f -iname "${allowed_extention}")
tput rc; tput el tput rc; tput el
echo -e "gathering ${directory} ${allowed_extention} : ${fileswc}..." echo -e "gathering ${directory} ${allowed_extention} : ${fileswc}..."
if [ ${fileswc} != 0 ]; then if [ ${fileswc} != 0 ]; then
@ -213,7 +213,7 @@ fn_fastdl_preview(){
# Calculates total file size. # Calculates total file size.
while read -r dufile; do while read -r dufile; do
filesize=$(stat -c %s "${dufile}") filesize=$(stat -c %s "${dufile}")
filesizetotal=$(( ${filesizetotal} + ${filesize} )) filesizetotal=$(( filesizetotal+filesize ))
exitcode=$? exitcode=$?
if [ "${exitcode}" != 0 ]; then if [ "${exitcode}" != 0 ]; then
fn_print_fail_eol_nl fn_print_fail_eol_nl

26
tests/tests_fctrserver.sh

@ -66,8 +66,6 @@ core_functions.sh(){
# Bootstrap # Bootstrap
# Fetches the core functions required before passed off to core_dl.sh. # Fetches the core functions required before passed off to core_dl.sh.
# Fetches core functions.
fn_bootstrap_fetch_file(){ fn_bootstrap_fetch_file(){
remote_fileurl="${1}" remote_fileurl="${1}"
local_filedir="${2}" local_filedir="${2}"
@ -280,15 +278,15 @@ if [ "$(whoami)" == "root" ]; then
fi fi
fi fi
# Download the latest serverlist. This is the complete list of all supported servers.
fn_bootstrap_fetch_file_github "lgsm/data" "serverlist.csv" "${datadir}" "nochmodx" "norun" "forcedl" "nomd5"
if [ ! -f "${serverlist}" ]; then
echo -e "[ FAIL ] serverlist.csv could not be loaded."
exit 1
fi
# LinuxGSM installer mode. # LinuxGSM installer mode.
if [ "${shortname}" == "core" ]; then if [ "${shortname}" == "core" ]; then
# Download the latest serverlist. This is the complete list of all supported servers.
fn_bootstrap_fetch_file_github "lgsm/data" "serverlist.csv" "${datadir}" "nochmodx" "norun" "forcedl" "nomd5"
if [ ! -f "${serverlist}" ]; then
echo -e "[ FAIL ] serverlist.csv could not be loaded."
exit 1
fi
if [ "${userinput}" == "list" ]||[ "${userinput}" == "l" ]; then if [ "${userinput}" == "list" ]||[ "${userinput}" == "l" ]; then
{ {
tail -n +2 "${serverlist}" | awk -F "," '{print $2 "\t" $3}' tail -n +2 "${serverlist}" | awk -F "," '{print $2 "\t" $3}'
@ -380,7 +378,7 @@ else
# Enables ANSI colours from core_messages.sh. Can be disabled with ansi=off. # Enables ANSI colours from core_messages.sh. Can be disabled with ansi=off.
fn_ansi_loader fn_ansi_loader
# Prevents running of core_exit.sh for Travis-CI. # Prevents running of core_exit.sh for Travis-CI.
if [ -z "${travistest}" ]; then if [ -z "${travistest}" ]; then
getopt=$1 getopt=$1
core_getopt.sh core_getopt.sh
fi fi
@ -480,6 +478,8 @@ fn_test_result_na(){
fn_print_fail_nl "TEST N/A" fn_print_fail_nl "TEST N/A"
} }
sleeptime="0"
echo -e "=================================" echo -e "================================="
echo -e "Travis CI Tests" echo -e "Travis CI Tests"
echo -e "Linux Game Server Manager" echo -e "Linux Game Server Manager"
@ -1011,6 +1011,8 @@ echo -e "Using: ${gamename}"
echo -e "=================================" echo -e "================================="
requiredstatus="OFFLINE" requiredstatus="OFFLINE"
fn_setstatus fn_setstatus
fn_print_info "Tidying up directories." if [ ! -v TRAVIS ]; then
rm -rfv "${serverfiles}" fn_print_info "Tidying up directories."
rm -rfv "${serverfiles}"
fi
core_exit.sh core_exit.sh

8
tests/tests_jc2server.sh

@ -478,6 +478,8 @@ fn_test_result_na(){
fn_print_fail_nl "TEST N/A" fn_print_fail_nl "TEST N/A"
} }
sleeptime="0"
echo -e "=================================" echo -e "================================="
echo -e "Travis CI Tests" echo -e "Travis CI Tests"
echo -e "Linux Game Server Manager" echo -e "Linux Game Server Manager"
@ -1170,6 +1172,8 @@ echo -e "Using: ${gamename}"
echo -e "=================================" echo -e "================================="
requiredstatus="OFFLINE" requiredstatus="OFFLINE"
fn_setstatus fn_setstatus
fn_print_info "Tidying up directories." if [ ! -v TRAVIS ]; then
rm -rfv "${serverfiles}" fn_print_info "Tidying up directories."
rm -rfv "${serverfiles}"
fi
core_exit.sh core_exit.sh

14
tests/tests_kcov.sh

@ -0,0 +1,14 @@
#!/bin/bash
echo -e "Installing kcov"
curl -L "https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/shunit2/shunit2-2.1.6.tgz" | tar zx
wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz
tar xzf master.tar.gz
cd kcov-master || exit
mkdir build
cd build || exit
cmake ..
make
sudo make install
cd ../..
rm -rf kcov-master
mkdir -p coverage

8
tests/tests_mcserver.sh

@ -478,6 +478,8 @@ fn_test_result_na(){
fn_print_fail_nl "TEST N/A" fn_print_fail_nl "TEST N/A"
} }
sleeptime="0"
echo -e "=================================" echo -e "================================="
echo -e "Travis CI Tests" echo -e "Travis CI Tests"
echo -e "Linux Game Server Manager" echo -e "Linux Game Server Manager"
@ -1056,6 +1058,8 @@ echo -e "Using: ${gamename}"
echo -e "=================================" echo -e "================================="
requiredstatus="OFFLINE" requiredstatus="OFFLINE"
fn_setstatus fn_setstatus
fn_print_info "Tidying up directories." if [ ! -v TRAVIS ]; then
rm -rfv "${serverfiles}" fn_print_info "Tidying up directories."
rm -rfv "${serverfiles}"
fi
core_exit.sh core_exit.sh

8
tests/tests_ts3server.sh

@ -478,6 +478,8 @@ fn_test_result_na(){
fn_print_fail_nl "TEST N/A" fn_print_fail_nl "TEST N/A"
} }
sleeptime="0"
echo -e "=================================" echo -e "================================="
echo -e "Travis CI Tests" echo -e "Travis CI Tests"
echo -e "Linux Game Server Manager" echo -e "Linux Game Server Manager"
@ -1009,6 +1011,8 @@ echo -e "Using: ${gamename}"
echo -e "=================================" echo -e "================================="
requiredstatus="OFFLINE" requiredstatus="OFFLINE"
fn_setstatus fn_setstatus
fn_print_info "Tidying up directories." if [ ! -v TRAVIS ]; then
rm -rfv "${serverfiles}" fn_print_info "Tidying up directories."
rm -rfv "${serverfiles}"
fi
core_exit.sh core_exit.sh

Loading…
Cancel
Save