Skip to content

Commit

Permalink
Testing: unit & shellcheck
Browse files Browse the repository at this point in the history
Some minor fixes
  • Loading branch information
matteocorti committed Feb 9, 2016
1 parent cb924b1 commit ef36697
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
@@ -0,0 +1,3 @@
[submodule "shell-ci-build"]
path = shell-ci-build
url = https://github.com/caarlos0/shell-ci-build.git
19 changes: 19 additions & 0 deletions .travis.yml
@@ -0,0 +1,19 @@
language: bash

sudo: required

os:
- linux
- osx

install:
- ./shell-ci-build/install.sh

before_script:
- curl -L "http://downloads.sourceforge.net/shunit2/shunit2-2.0.3.tgz" | tar zx
- chmod +x $(pwd)/shunit2-2.0.3/src/shell/shunit2

script:
- export SHUNIT2=$(pwd)/shunit2-2.0.3/src/shell/shunit2
- make test
- ./shell-ci-build.sh
1 change: 1 addition & 0 deletions shell-ci-build
Submodule shell-ci-build added at 3ecb8b
4 changes: 4 additions & 0 deletions shell-ci-build.sh
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -eo pipefail
source ./shell-ci-build/build.sh
check "./check_nagios_latency"
47 changes: 47 additions & 0 deletions test/unit_tests.sh
@@ -0,0 +1,47 @@
#!/bin/sh

if [ -z "${SHUNIT2}" ] ; then
cat <<EOF
To be able to run the unit test you need a copy of shUnit2
You can download it from http://shunit2.googlecode.com/
Once downloaded please set the SHUNIT2 variable with the location
of the 'shunit2' script
EOF
exit 1
fi

if [ ! -x "${SHUNIT2}" ] ; then
echo "Error: the specified shUnit2 script (${SHUNIT2}) is not an executable file"
exit 1
fi

SCRIPT=../check_nagios_latency
if [ ! -r "${SCRIPT}" ] ; then
echo "Error: the script to test (${SCRIPT}) is not a readable file"
fi

# constants

NAGIOS_OK=0
NAGIOS_CRITICAL=1
NAGIOS_WARNING=2
NAGIOS_UNKNOWN=3

testUsage() {
${SCRIPT} > /dev/null 2>&1
EXIT_CODE=$?
assertEquals "wrong exit code" ${NAGIOS_UNKNOWN} "${EXIT_CODE}"
}

# the script will exit without executing main
export SOURCE_ONLY='test'

# source the script.
. ${SCRIPT}

unset SOURCE_ONLY

# run shUnit: it will execute all the tests in this file
# (e.g., functions beginning with 'test'
. ${SHUNIT2}

0 comments on commit ef36697

Please sign in to comment.