github.com/crowdsecurity/crowdsec@v1.6.1/test/ansible/roles/run_func_tests/tasks/main.yml (about)

     1  # vim: set ft=yaml.ansible:
     2  ---
     3  - name: "Tweak systemd configuration for tests"
     4    become: true
     5    block:
     6      - name: "Create /lib/systemd/system/crowdsec.service.d"
     7        ansible.builtin.file:
     8          owner: root
     9          group: root
    10          mode: 0o755
    11          path: /lib/systemd/system/crowdsec.service.d
    12          state: directory
    13      - name: "Override StartLimitBurst"
    14        ansible.builtin.ini_file:
    15          dest: /lib/systemd/system/crowdsec.service.d/startlimitburst.conf
    16          owner: root
    17          group: root
    18          mode: 0o644
    19          section: Service
    20          option: StartLimitBurst
    21          value: 100
    22      - name: "Systemctl daemon-reload"
    23        ansible.builtin.systemd:
    24          daemon_reload: true
    25    when:
    26      - (package_testing is defined) and (package_testing not in ['', 'false', 'False'])
    27      - ansible_facts.os_family in ["RedHat", "Debian"]
    28  
    29  - name: "Debug - show environment.sh"
    30    become: false
    31    block:
    32      - name: "Look for .environment.sh"
    33        ansible.builtin.slurp:
    34          src: "{{ ansible_env.HOME }}/crowdsec/test/.environment.sh"
    35        changed_when: true
    36        register: envfile
    37      - name: "Show .environment.sh"
    38        ansible.builtin.debug:
    39          msg: "{{ envfile['content'] | b64decode }}"
    40  
    41  - name: "Search for test scripts"
    42    become: false
    43    ansible.builtin.find:
    44      paths: "{{ ansible_env.HOME }}/crowdsec/test/bats"
    45      pattern: "*.bats"
    46    register: testfiles
    47  
    48  - name: "Run BATS tests for source build"
    49    become: false
    50    block:
    51      - name: "Run test scripts"
    52        ansible.builtin.command:
    53          cmd: test/run-tests {{ item.path }}
    54          chdir: "{{ ansible_env.HOME }}/crowdsec"
    55        with_items: "{{ testfiles.files | sort(attribute='path') }}"
    56        loop_control:
    57          label: "{{ item['path'] }}"
    58        environment:
    59          # daemonize -> /usr/bin or /usr/local/sbin
    60          # pidof -> /usr/sbin
    61          # bash -> /opt/bash/bin
    62          PATH: "/opt/bash/bin:{{ ansible_env.PATH }}:/usr/sbin:/usr/local/sbin"
    63        changed_when: true
    64        when:
    65          - (item.path | basename) not in skip_tests.split(',')
    66    rescue:
    67      - name: "Read crowdsec.log"
    68        ansible.builtin.slurp:
    69          path: "{{ ansible_env.HOME }}/crowdsec/test/local/var/log/crowdsec.log"
    70        register: crowdsec_log
    71      - name: "Show crowdsec.log"
    72        ansible.builtin.fail:
    73          msg: "{{ crowdsec_log['content'] | b64decode }}"
    74    when:
    75      - (package_testing is not defined) or (package_testing in ['', 'false', 'False'])
    76  
    77  - name: "Run BATS tests for binary package"
    78    become: true
    79    block:
    80      - name: "Run test scripts"
    81        ansible.builtin.command:
    82          cmd: test/run-tests {{ item.path }}
    83          chdir: "{{ ansible_env.HOME }}/crowdsec"
    84        with_items: "{{ testfiles.files | sort(attribute='path') }}"
    85        loop_control:
    86          label: "{{ item['path'] }}"
    87        environment:
    88          # daemonize -> /usr/bin or /usr/local/sbin
    89          # pidof -> /usr/sbin
    90          # bash -> /opt/bash/bin
    91          PATH: "/opt/bash/bin:{{ ansible_env.PATH }}:/usr/sbin:/usr/local/sbin"
    92        changed_when: true
    93        when:
    94          - (item.path | basename) not in skip_tests.split(',')
    95    rescue:
    96      - name: "Read crowdsec.log"
    97        ansible.builtin.slurp:
    98          path: "/var/log/crowdsec.log"
    99        register: crowdsec_log
   100      - name: "Show crowdsec.log"
   101        ansible.builtin.fail:
   102          msg: "{{ crowdsec_log['content'] | b64decode }}"
   103    when:
   104      - (package_testing is defined) and (package_testing not in ['', 'false', 'False'])