Bats: "reformat" script for shfmt, longer timeout for crowdsec (#1373)
This commit is contained in:
parent
af8c55330d
commit
c2708ab6c0
|
@ -41,10 +41,10 @@ declare stderr
|
||||||
|
|
||||||
@test "$FILE cscli alerts list: at startup returns at least one entry: community pull" {
|
@test "$FILE cscli alerts list: at startup returns at least one entry: community pull" {
|
||||||
loop_max=15
|
loop_max=15
|
||||||
for ((i=0; i<=loop_max; i++)); do
|
for ((i = 0; i <= loop_max; i++)); do
|
||||||
sleep 2
|
sleep 2
|
||||||
run -0 cscli alerts list -o json
|
run -0 cscli alerts list -o json
|
||||||
[[ "$output" != "null" ]] && break
|
[ "$output" != "null" ] && break
|
||||||
done
|
done
|
||||||
run -0 jq -r '. | length' <(output)
|
run -0 jq -r '. | length' <(output)
|
||||||
refute_output 0
|
refute_output 0
|
||||||
|
|
|
@ -26,17 +26,17 @@ declare stderr
|
||||||
#----------
|
#----------
|
||||||
|
|
||||||
@test "$FILE test without -no-api flag" {
|
@test "$FILE test without -no-api flag" {
|
||||||
run -124 --separate-stderr timeout 1s "${CROWDSEC}"
|
run -124 --separate-stderr timeout 2s "${CROWDSEC}"
|
||||||
# from `man timeout`: If the command times out, and --preserve-status is not set, then exit with status 124.
|
# from `man timeout`: If the command times out, and --preserve-status is not set, then exit with status 124.
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "$FILE crowdsec should not run without LAPI (-no-api flag)" {
|
@test "$FILE crowdsec should not run without LAPI (-no-api flag)" {
|
||||||
run -1 --separate-stderr timeout 1s "${CROWDSEC}" -no-api
|
run -1 --separate-stderr timeout 2s "${CROWDSEC}" -no-api
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "$FILE crowdsec should not run without LAPI (no api.server in configuration file)" {
|
@test "$FILE crowdsec should not run without LAPI (no api.server in configuration file)" {
|
||||||
yq 'del(.api.server)' -i "${CONFIG_YAML}"
|
yq 'del(.api.server)' -i "${CONFIG_YAML}"
|
||||||
run -1 --separate-stderr timeout 1s "${CROWDSEC}"
|
run -1 --separate-stderr timeout 2s "${CROWDSEC}"
|
||||||
|
|
||||||
run -0 echo "$stderr"
|
run -0 echo "$stderr"
|
||||||
assert_output --partial "crowdsec local API is disabled"
|
assert_output --partial "crowdsec local API is disabled"
|
||||||
|
|
|
@ -29,17 +29,17 @@ config_disable_agent() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "$FILE with agent: test without -no-cs flag" {
|
@test "$FILE with agent: test without -no-cs flag" {
|
||||||
run -124 timeout 1s "${CROWDSEC}"
|
run -124 timeout 2s "${CROWDSEC}"
|
||||||
# from `man timeout`: If the command times out, and --preserve-status is not set, then exit with status 124.
|
# from `man timeout`: If the command times out, and --preserve-status is not set, then exit with status 124.
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "$FILE no agent: crowdsec LAPI should run (-no-cs flag)" {
|
@test "$FILE no agent: crowdsec LAPI should run (-no-cs flag)" {
|
||||||
run -124 timeout 1s "${CROWDSEC}" -no-cs
|
run -124 timeout 2s "${CROWDSEC}" -no-cs
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "$FILE no agent: crowdsec LAPI should run (no crowdsec_service in configuration file)" {
|
@test "$FILE no agent: crowdsec LAPI should run (no crowdsec_service in configuration file)" {
|
||||||
config_disable_agent
|
config_disable_agent
|
||||||
run -124 --separate-stderr timeout 1s "${CROWDSEC}"
|
run -124 --separate-stderr timeout 2s "${CROWDSEC}"
|
||||||
|
|
||||||
run -0 echo "$stderr"
|
run -0 echo "$stderr"
|
||||||
assert_output --partial "crowdsec agent is disabled"
|
assert_output --partial "crowdsec agent is disabled"
|
||||||
|
|
|
@ -42,4 +42,3 @@ teardown() {
|
||||||
assert_output --partial "| 'githubciXXXXXXXXXXXXXXXXXXXXXXXX' |"
|
assert_output --partial "| 'githubciXXXXXXXXXXXXXXXXXXXXXXXX' |"
|
||||||
assert_output --partial "| githubciXXXXXXXXXXXXXXXXXXXXXXXX |"
|
assert_output --partial "| githubciXXXXXXXXXXXXXXXXXXXXXXXX |"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,4 +56,3 @@ declare stderr
|
||||||
assert_output --partial "| 'githubciXXXXXXXXXXXXXXXXXXXXXXXX' |"
|
assert_output --partial "| 'githubciXXXXXXXXXXXXXXXXXXXXXXXX' |"
|
||||||
assert_output --partial "| githubciXXXXXXXXXXXXXXXXXXXXXXXX |"
|
assert_output --partial "| githubciXXXXXXXXXXXXXXXXXXXXXXXX |"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,8 +37,6 @@ api() {
|
||||||
run -0 cscli decisions list -o json
|
run -0 cscli decisions list -o json
|
||||||
run -0 jq -r '.[0].decisions[0].value' <(output)
|
run -0 jq -r '.[0].decisions[0].value' <(output)
|
||||||
assert_output '4.4.4.0/24'
|
assert_output '4.4.4.0/24'
|
||||||
# run -0 jq -c '[ .[0].decisions[0].value, .[1].decisions[0].value ]' <(output)
|
|
||||||
# assert_output '["4.4.4.0/24","1.2.3.4"]'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "$FILE API - all decisions" {
|
@test "$FILE API - all decisions" {
|
||||||
|
|
|
@ -49,7 +49,6 @@ api() {
|
||||||
refute_output --partial 'toto'
|
refute_output --partial 'toto'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@test "$FILE stream start (user scope)" {
|
@test "$FILE stream start (user scope)" {
|
||||||
run -0 api "/v1/decisions/stream?startup=true&scopes=user"
|
run -0 api "/v1/decisions/stream?startup=true&scopes=user"
|
||||||
run -0 jq -r '.new' <(output)
|
run -0 jq -r '.new' <(output)
|
||||||
|
@ -57,7 +56,6 @@ api() {
|
||||||
assert_output --partial 'toto'
|
assert_output --partial 'toto'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@test "$FILE stream start (user+ip scope)" {
|
@test "$FILE stream start (user+ip scope)" {
|
||||||
run -0 api "/v1/decisions/stream?startup=true&scopes=user,ip"
|
run -0 api "/v1/decisions/stream?startup=true&scopes=user,ip"
|
||||||
run -0 jq -r '.new' <(output)
|
run -0 jq -r '.new' <(output)
|
||||||
|
|
|
@ -52,7 +52,6 @@ api() {
|
||||||
assert_output --partial '1.2.3.5'
|
assert_output --partial '1.2.3.5'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@test "$FILE stream cont (del)" {
|
@test "$FILE stream cont (del)" {
|
||||||
sleep 1
|
sleep 1
|
||||||
run -0 cscli decisions delete -i '1.2.3.4'
|
run -0 cscli decisions delete -i '1.2.3.4'
|
||||||
|
|
16
tests/bats/reformat
Executable file
16
tests/bats/reformat
Executable file
|
@ -0,0 +1,16 @@
|
||||||
|
|
||||||
|
# from https://github.com/bats-core/bats-core/issues/192#issuecomment-528315083
|
||||||
|
# thanks Sean Leather
|
||||||
|
|
||||||
|
# Rewrite the Bats scripts in-place to look more like Bash scripts to shfmt
|
||||||
|
perl -pi -e 's/^(\@test.*) \{$/$1\n{/' ./*.bats
|
||||||
|
|
||||||
|
tmpfile=$(mktemp)
|
||||||
|
for file in *bats; do
|
||||||
|
shfmt -i 4 -ln bash -s $file >$tmpfile
|
||||||
|
mv $tmpfile $file
|
||||||
|
done
|
||||||
|
rm -f $tmpfile
|
||||||
|
|
||||||
|
# Undo the changes to the Bats scripts in-place so that they work with Bats
|
||||||
|
perl -pi -e 's/^\{\R//; s/(\@test.*$)/$1 {/' ./*.bats
|
Loading…
Reference in a new issue