crowdsec/scripts/func_tests/tests_base.sh
Manuel Sabban 6b5f272c0a
Func tests (#970)
* stabilize func tests
* fix cold logs func tests
* add wait condition on mock server

Co-authored-by: sabban <15465465+sabban@users.noreply.github.com>
2021-09-13 17:33:47 +02:00

52 lines
1.1 KiB
Bash
Executable file

#! /usr/bin/env bash
# -*- coding: utf-8 -*-
# sourced by other functionnal tests
PACKAGE_PATH="${PACKAGE_PATH:-./crowdsec.deb}"
CSCLI_BIN="cscli"
CSCLI="sudo ${CSCLI_BIN}"
JQ="jq -e"
LC_ALL=C
SYSTEMCTL="sudo systemctl --no-pager"
CROWDSEC="sudo crowdsec"
CROWDSEC_PROCESS="crowdsec"
# helpers
function fail {
echo "ACTION FAILED, STOP : $@"
caller
exit 1
}
function pathadd {
if [ -d "$1" ] && [[ ":$PATH:" != *":$1:"* ]]; then
PATH="${PATH:+"$PATH:"}$1"
fi
}
function wait_for_service {
count=0
while ! nc -z localhost 6060; do
sleep 0.5
((count ++))
if [[ count == 21 ]]; then
fail "$@"
fi
done
}
pathadd /usr/sbin
if [ -f /etc/systemd/system/crowdsec.service ]; then
SYSTEMD_SERVICE_FILE=/etc/systemd/system/crowdsec.service
elif [ -f /usr/lib/systemd/system/crowdsec.service ]; then
SYSTEMD_SERVICE_FILE=/usr/lib/systemd/system/crowdsec.service
elif [ -f /lib/systemd/system/crowdsec.service ]; then
SYSTEMD_SERVICE_FILE=/lib/systemd/system/crowdsec.service
fi