mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-06 15:17:01 +02:00
`make unit-tests` would run shell scripts from tests/unit/ The run-unittests.sh script will look for any .sh in tests/unit/ and will call it twice: - first with the 'check' argument in order to decide if we should skip the test or not - second to run the check A simple test could be written this way: #!/bin/sh check() { ${HAPROXY_PROGRAM} -cc 'feature(OPENSSL)' command -v socat } run() { ${HAPROXY_PROGRAM} -dI -f ${ROOTDIR}/examples/quick-test.cfg -c } case "$1" in "check") check ;; "run") run ;; esac The tests *MUST* be written in POSIX shell in order to be portable, and any special commands should be tested with `command -v` before using it. Tests are run with `sh -e` so everything must be tested.
87 lines
2.2 KiB
Bash
Executable File
87 lines
2.2 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
export HAPROXY_PROGRAM="${HAPROXY_PROGRAM:-${PWD}/haproxy}"
|
|
export HAPROXY_ARGS="${HAPROXY_ARGS--dM -dI -dW}"
|
|
export ROOTDIR="${ROOTDIR:-${PWD}}"
|
|
export TESTDIR="${TESTDIR:-./tests/unit/}"
|
|
|
|
result=0
|
|
|
|
echo ""
|
|
echo "########################## Preparing to run unit tests ##########################"
|
|
|
|
preparefailed=
|
|
if ! [ -x "$(command -v $HAPROXY_PROGRAM)" ]; then
|
|
echo "haproxy not found in path, please specify HAPROXY_PROGRAM environment variable"
|
|
preparefailed=1
|
|
fi
|
|
if [ $preparefailed ]; then
|
|
exit 1
|
|
fi
|
|
|
|
{ read HAPROXY_VERSION; read TARGET; read FEATURES; read SERVICES; } << EOF
|
|
$($HAPROXY_PROGRAM $HAPROXY_ARGS -vv | grep -E 'HA-?Proxy version|TARGET.*=|^Feature|^Available services' | sed 's/.* [:=] //')
|
|
EOF
|
|
|
|
UNITTESTS=$($HAPROXY_PROGRAM $HAPROXY_ARGS -vv|grep -E '^Unit tests list' | sed 's/.* [:=] //')
|
|
if [ -z "$UNITTESTS" ]; then
|
|
UNITTESTS="none"
|
|
fi
|
|
|
|
HAPROXY_VERSION=$(echo $HAPROXY_VERSION | cut -d " " -f 3)
|
|
echo "Testing with haproxy version: $HAPROXY_VERSION"
|
|
|
|
PROJECT_VERSION=$(${MAKE:-make} version 2>&1 | grep -E '^VERSION:|^SUBVERS:'|cut -f2 -d' '|tr -d '\012')
|
|
if [ -z "${PROJECT_VERSION}${MAKE}" ]; then
|
|
# try again with gmake, just in case
|
|
PROJECT_VERSION=$(gmake version 2>&1 | grep -E '^VERSION:|^SUBVERS:'|cut -f2 -d' '|tr -d '\012')
|
|
fi
|
|
FEATURES_PATTERN=" $FEATURES "
|
|
SERVICES_PATTERN=" $SERVICES "
|
|
|
|
echo "Target : $TARGET"
|
|
echo "Options : $FEATURES"
|
|
echo "Services : $SERVICES"
|
|
echo "Unit tests: $UNITTESTS"
|
|
|
|
succeed=0
|
|
failed=0
|
|
skipped=0
|
|
testlist=
|
|
|
|
echo "########################## Gathering tests to run ##########################"
|
|
|
|
for test in $(find "$TESTDIR" -name "*.sh"); do
|
|
sh ${test} check
|
|
r="$?"
|
|
if [ "$r" = "0" ]; then
|
|
echo " Add test: $test"
|
|
testlist="$testlist $test"
|
|
else
|
|
skipped=$((skipped+1))
|
|
echo " Skip $test"
|
|
fi
|
|
done
|
|
|
|
echo "########################## Starting unit tests ##########################"
|
|
|
|
for TEST in $testlist; do
|
|
# echo "*** run ${TEST}"
|
|
export TEST
|
|
export TESTDIR=`dirname ${TEST}`
|
|
|
|
sh -e ${TEST} run
|
|
r="$?"
|
|
# echo "*** result ${TEST}: $r"
|
|
if [ "$r" != "0" ]; then
|
|
result=$r
|
|
failed=$((failed+1))
|
|
else
|
|
succeed=$((succeed+1))
|
|
fi
|
|
done
|
|
|
|
echo "${failed} tests failed, ${skipped} tests skipped, ${succeed} tests passed"
|
|
|
|
exit $result
|