github.com/crowdsecurity/crowdsec@v1.6.1/test/bats-detect/openresty-deb.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 deb-remove openresty 14 } 15 16 setup() { 17 if ! command -v dpkg >/dev/null; then 18 skip 'not a debian-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 deb-install debian-keyring debian-archive-keyring apt-transport-https 35 run -0 curl -1sSLf 'https://openresty.org/package/pubkey.gpg' 36 if [[ "$(lsb_release -is)" == "Ubuntu" ]]; then 37 run -0 sudo gpg --yes --dearmor -o /usr/share/keyrings/openresty.gpg < <(output) 38 run -0 sudo tee <<< "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/openresty.gpg] http://openresty.org/package/ubuntu $(lsb_release -sc) main" /etc/apt/sources.list.d/openresty.list 39 else 40 release="$(lsb_release -sc)" 41 # Debian 12 package is not available as of 2023-07-3 42 if [[ "$release" == "bookworm" ]]; then 43 release="bullseye" 44 fi 45 run -0 sudo apt-key add - < <(output) 46 run -0 sudo tee <<< "deb http://openresty.org/package/debian $release openresty" /etc/apt/sources.list.d/openresty.list 47 fi 48 run -0 deb-update 49 run -0 deb-install openresty 50 run -0 sudo systemctl enable openresty.service 51 } 52 53 @test "openresty: detect unit (succeed)" { 54 run -0 cscli setup detect 55 run -0 jq -r '.setup | .[].detected_service' <(output) 56 assert_line 'openresty-systemd' 57 } 58 59 @test "openresty: install detected collection" { 60 run -0 cscli setup detect 61 run -0 cscli setup install-hub <(output) 62 }