github.com/crowdsecurity/crowdsec@v1.6.1/test/bats-detect/pgsql-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  cleanup() {
     7      command -v dpkg >/dev/null || return 0
     8      # sudo systemctl stop postgresql.service || :
     9      # remove the DB to avoid a prompt from postrm
    10      if [[ -d /var/lib/postgresql ]]; then
    11          # shellcheck disable=SC2045
    12          for cluster in $(ls /var/lib/postgresql 2>/dev/null); do
    13              sudo pg_dropcluster --stop "${cluster}" main
    14          done
    15      fi
    16      deb-remove postgresql $(dpkg -l | grep postgres | awk '{print $2}')
    17  }
    18  
    19  setup_file() {
    20      load "../lib/setup_file.sh"
    21      load "${BATS_TEST_DIRNAME}/lib/setup_file_detect.sh"
    22      cleanup
    23  }
    24  
    25  teardown_file() {
    26      load "../lib/teardown_file.sh"
    27      cleanup
    28  }
    29  
    30  setup() {
    31      if ! command -v dpkg >/dev/null; then
    32          skip 'not a debian-like system'
    33      fi
    34      load "../lib/setup.sh"
    35      load "../lib/bats-file/load.bash"
    36      ./instance-data load
    37  }
    38  
    39  #----------
    40  
    41  @test "pgsql: detect unit (fail)" {
    42      run -0 cscli setup detect
    43      run -0 jq -r '.setup | .[].detected_service' <(output)
    44      refute_line 'pgsql-systemd-deb'
    45  }
    46  
    47  @test "pgsql: install" {
    48      run -0 deb-install postgresql
    49      run -0 sudo systemctl enable postgresql.service
    50  }
    51  
    52  @test "pgsql: detect unit (succeed)" {
    53      run -0 cscli setup detect
    54      run -0 jq -r '.setup | .[].detected_service' <(output)
    55      assert_line 'pgsql-systemd-deb'
    56  }
    57  
    58  @test "pgsql: install detected collection" {
    59      run -0 cscli setup detect
    60      run -0 cscli setup install-hub <(output)
    61  }