github.com/crowdsecurity/crowdsec@v1.6.1/test/bats-detect/mysql-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      # debian: mysql-community-server
    14      # ubuntu: mysql-server
    15      deb-remove mysql-server mysql-community-server
    16  }
    17  
    18  setup() {
    19      if ! command -v dpkg >/dev/null; then
    20          skip 'not a debian-like system'
    21      fi
    22      load "../lib/setup.sh"
    23      load "../lib/bats-file/load.bash"
    24      ./instance-data load
    25      if apt-cache search --names-only "^mysql-server$"; then
    26          skip "mysql-server package not available"
    27      fi
    28  }
    29  
    30  #----------
    31  
    32  @test "mysql: detect unit (fail)" {
    33      run -0 cscli setup detect
    34      run -0 jq -r '.setup | .[].detected_service' <(output)
    35      refute_line 'mysql-systemd'
    36  }
    37  
    38  @test "mysql: install" {
    39      # ubuntu comes with mysql, debian does not
    40      if apt-cache search --names-only "^mysql-server$"; then
    41          # package not available, install the repo
    42          filename="mysql-apt-config_0.8.23-1_all.deb"
    43          run -0 curl -1sSLf "https://dev.mysql.com/get/${filename}" -o "${CACHEDIR}/${filename}"
    44          # XXX md5 c2b410031867dc7c966ca5b1aa0c72aa
    45          run -0 sudo dpkg --install "${CACHEDIR}/${filename}"
    46          run -0 deb-update
    47          # XXX this hangs
    48          run -0 deb-install mysql-community-server
    49      else
    50      	run -0 deb-install mysql-server
    51      fi
    52      run -0 sudo systemctl enable mysql.service
    53  }
    54  
    55  @test "mysql: detect unit (succeed)" {
    56      run -0 cscli setup detect
    57      run -0 jq -r '.setup | .[].detected_service' <(output)
    58      assert_line 'mysql-systemd'
    59  }
    60  
    61  @test "mysql: install detected collection" {
    62      run -0 cscli setup detect
    63      run -0 cscli setup install-hub <(output)
    64  }