crowdsec/tests/generate-hub-tests
mmetc af8c55330d
[wip] bats changes for modular fixtures (#1371)
* target: tests/.environment.sh
* don't pass BIN_DIR around
* manage db backup/restore separately
* don't export CONFIG_DIR, DATA_DIR (derive path locations from
CONFIG_YAML); redirect stdout, stderr to &3 by default in setup_file,
teardown_file
2022-03-18 10:13:12 +01:00

51 lines
1.1 KiB
Bash
Executable file

#!/bin/sh
set -eu
# shellcheck disable=SC1007
TEST_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
# shellcheck source=./.environment.sh
. "${TEST_DIR}/.environment.sh"
cscli() {
"${CSCLI}" "$@"
}
"${TEST_DIR}/instance-data" load
hubdir="${LOCAL_DIR}/hub-tests"
git clone --depth 1 https://github.com/crowdsecurity/hub.git "${hubdir}" >/dev/null 2>&1 || (cd "${hubdir}"; git pull)
HUBTESTS_BATS="${TEST_DIR}/dyn-bats/99_hub.bats"
cat << EOT > "${HUBTESTS_BATS}"
set -u
setup_file() {
load "../lib/setup_file.sh" >&3 2>&1
}
teardown_file() {
load "../lib/teardown_file.sh" >&3 2>&1
}
setup() {
load "../lib/setup.sh"
}
EOT
echo "Generating hub tests..."
for testname in $("${CSCLI}" --crowdsec "${CROWDSEC}" --cscli "${CSCLI}" hubtest --hub "${hubdir}" list -o json | grep -v NAME | grep -v -- '-------' | awk '{print $1}'); do
cat << EOT >> "${HUBTESTS_BATS}"
@test "\$FILE $testname" {
run "\${CSCLI}" --crowdsec "\${CROWDSEC}" --cscli "\${CSCLI}" --hub "${hubdir}" hubtest run "${testname}" --clean
# in case of error, need to see what went wrong
echo "\$output"
assert_success
}
EOT
done