github.com/crowdsecurity/crowdsec@v1.6.1/test/bats-detect/openresty-rpm.bats (about) 1 #!/usr/bin/env bats 2 # vim: ft=bats:list:ts=8:sts=4:sw=4:et:ai:si: 3 4 set -u 5 6 setup_file() { 7 load "../lib/setup_file.sh" 8 load "${BATS_TEST_DIRNAME}/lib/setup_file_detect.sh" 9 } 10 11 teardown_file() { 12 load "../lib/teardown_file.sh" 13 rpm-remove openresty 14 } 15 16 setup() { 17 if ! command -v dnf >/dev/null; then 18 skip 'not a redhat-like system' 19 fi 20 load "../lib/setup.sh" 21 load "../lib/bats-file/load.bash" 22 ./instance-data load 23 } 24 25 #---------- 26 27 @test "openresty: detect unit (fail)" { 28 run -0 cscli setup detect 29 run -0 jq -r '.setup | .[].detected_service' <(output) 30 refute_line 'openresty-systemd' 31 } 32 33 @test "openresty: install" { 34 run -0 rpm-install redhat-lsb-core 35 if [[ "$(lsb_release -is)" == "Fedora" ]]; then 36 run -0 sudo curl -1sSLf "https://openresty.org/package/fedora/openresty.repo" -o "/etc/yum.repos.d/openresty.repo" 37 elif [[ "$(lsb_release -is)" == CentOS* ]]; then # must match CentOSStream 38 run -0 sudo curl -1sSLf "https://openresty.org/package/centos/openresty.repo" -o "/etc/yum.repos.d/openresty.repo" 39 fi 40 run sudo dnf check-update 41 # 0 = up to date, 100 = updates available 42 if [[ "$status" -ne 0 ]] && [[ "$status" -ne 100 ]]; then 43 fail "dnf check-update failed with status $status" 44 fi 45 run -0 rpm-install openresty 46 run -0 sudo systemctl enable openresty.service 47 } 48 49 @test "openresty: detect unit (succeed)" { 50 run -0 cscli setup detect 51 run -0 jq -r '.setup | .[].detected_service' <(output) 52 assert_line 'openresty-systemd' 53 } 54 55 @test "openresty: install detected collection" { 56 run -0 cscli setup detect 57 run -0 cscli setup install-hub <(output) 58 }