crowdsec/test/ansible/roles/run_func_tests/tasks/main.yml
mmetc a19748ae35
Rename directory "tests" to "test" (#2094)
If you use a ./test/local directory, you need to create it again:
$ make clean bats-build bats-fixture
2023-03-03 15:54:49 +01:00

105 lines
3.4 KiB
YAML

# vim: set ft=yaml.ansible:
---
- name: "Tweak systemd configuration for tests"
become: true
block:
- name: "Create /lib/systemd/system/crowdsec.service.d"
ansible.builtin.file:
owner: root
group: root
mode: 0o755
path: /lib/systemd/system/crowdsec.service.d
state: directory
- name: "Override StartLimitBurst"
ansible.builtin.ini_file:
dest: /lib/systemd/system/crowdsec.service.d/startlimitburst.conf
owner: root
group: root
mode: 0o644
section: Service
option: StartLimitBurst
value: 100
- name: "Systemctl daemon-reload"
ansible.builtin.systemd:
daemon_reload: true
when:
- (package_testing is defined) and (package_testing not in ['', 'false', 'False'])
- ansible_facts.os_family in ["RedHat", "Debian"]
- name: "Debug - show environment.sh"
become: false
block:
- name: "Look for .environment.sh"
ansible.builtin.slurp:
src: "{{ ansible_env.HOME }}/crowdsec/test/.environment.sh"
changed_when: true
register: envfile
- name: "Show .environment.sh"
ansible.builtin.debug:
msg: "{{ envfile['content'] | b64decode }}"
- name: "Search for test scripts"
become: false
ansible.builtin.find:
paths: "{{ ansible_env.HOME }}/crowdsec/test/bats"
pattern: "*.bats"
register: testfiles
- name: "Run BATS tests for source build"
become: false
block:
- name: "Run test scripts"
ansible.builtin.command:
cmd: test/run-tests {{ item.path }}
chdir: "{{ ansible_env.HOME }}/crowdsec"
with_items: "{{ testfiles.files | sort(attribute='path') }}"
loop_control:
label: "{{ item['path'] }}"
environment:
# daemonize -> /usr/bin or /usr/local/sbin
# pidof -> /usr/sbin
# bash -> /opt/bash/bin
PATH: "/opt/bash/bin:{{ ansible_env.PATH }}:/usr/sbin:/usr/local/sbin"
changed_when: true
when:
- (item.path | basename) not in skip_tests.split(',')
rescue:
- name: "Read crowdsec.log"
ansible.builtin.slurp:
path: "{{ ansible_env.HOME }}/crowdsec/test/local/var/log/crowdsec.log"
register: crowdsec_log
- name: "Show crowdsec.log"
ansible.builtin.fail:
msg: "{{ crowdsec_log['content'] | b64decode }}"
when:
- (package_testing is not defined) or (package_testing in ['', 'false', 'False'])
- name: "Run BATS tests for binary package"
become: true
block:
- name: "Run test scripts"
ansible.builtin.command:
cmd: test/run-tests {{ item.path }}
chdir: "{{ ansible_env.HOME }}/crowdsec"
with_items: "{{ testfiles.files | sort(attribute='path') }}"
loop_control:
label: "{{ item['path'] }}"
environment:
# daemonize -> /usr/bin or /usr/local/sbin
# pidof -> /usr/sbin
# bash -> /opt/bash/bin
PATH: "/opt/bash/bin:{{ ansible_env.PATH }}:/usr/sbin:/usr/local/sbin"
changed_when: true
when:
- (item.path | basename) not in skip_tests.split(',')
rescue:
- name: "Read crowdsec.log"
ansible.builtin.slurp:
path: "/var/log/crowdsec.log"
register: crowdsec_log
- name: "Show crowdsec.log"
ansible.builtin.fail:
msg: "{{ crowdsec_log['content'] | b64decode }}"
when:
- (package_testing is defined) and (package_testing not in ['', 'false', 'False'])