50 lines
1.1 KiB
Bash
Executable file
50 lines
1.1 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
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/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 "${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
|