Debian Codegraph @

tests/bin/generate-hub-tests

raw symbols SCIP
1 #!/usr/bin/env bash
2
3 set -eu
4
5 # shellcheck disable=SC1007
6 THIS_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
7 # shellcheck disable=SC1091
8 . "${THIS_DIR}/../.environment.sh"
9
10 cscli() {
11 "${CSCLI}" "$@"
12 }
13
14 "${TEST_DIR}/instance-data" load
15
16 hubdir="${LOCAL_DIR}/hub-tests"
17 git clone --depth 1 https://github.com/crowdsecurity/hub.git "${hubdir}" >/dev/null 2>&1 || (cd "${hubdir}"; git pull)
18
19 HUBTESTS_BATS="${TEST_DIR}/dyn-bats/hub.bats"
20
21 cat << EOT > "${HUBTESTS_BATS}"
22 set -u
23
24 setup_file() {
25 load "../lib/setup_file.sh"
26 }
27
28 teardown_file() {
29 load "../lib/teardown_file.sh"
30 }
31
32 setup() {
33 load "../lib/setup.sh"
34 }
35
36 EOT
37
38 echo "Generating hub tests..."
39
40 for testname in $("${CSCLI}" --crowdsec "${CROWDSEC}" --cscli "${CSCLI}" hubtest --hub "${hubdir}" list -o json | jq -r '.[] | .Name'); do
41 cat << EOT >> "${HUBTESTS_BATS}"
42
43 @test "${testname}" {
44 run "\${CSCLI}" --crowdsec "\${CROWDSEC}" --cscli "\${CSCLI}" --hub "${hubdir}" hubtest run "${testname}" --clean
45 # in case of error, need to see what went wrong
46 echo "\$output"
47 assert_success
48 }
49 EOT
50 done