1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2026-05-05 17:55:11 +00:00

add integration tests + fixes

This commit is contained in:
Simon Kelly 2020-10-16 15:04:06 +02:00
parent 00152dbb63
commit 816f31c19f
13 changed files with 393 additions and 25 deletions

View file

@ -0,0 +1,53 @@
####################################################################
# WARNING: These are designed specifically for Ansible tests #
# and should not be used as examples of how to write Ansible roles #
####################################################################
- block:
- name: install monit
become: yes
package:
name: monit
state: present
- name: monit config
become: yes
template:
src: "monitrc.j2"
dest: "/etc/monit/monitrc"
- name: process monit config
become: yes
template:
src: "httpd_echo.j2"
dest: "/etc/monit/conf.d/httpd_echo"
- name: copy process file
become: yes
copy:
src: "{{item}}"
dest: "/opt/{{item}}"
loop:
- daemon.py
- httpd_echo.py
- name: restart monit
become: yes
service:
name: monit
state: restarted
- include_tasks: test.yml
always:
- name: stop monit
become: yes
service:
name: monit
state: stopped
- name: uninstall monit
become: yes
package:
name: monit
state: absent

View file

@ -0,0 +1,26 @@
# order is important
- import_tasks: test_state.yml
vars:
state: stopped
initial_state: up
expected_state: down
- import_tasks: test_state.yml
vars:
state: started
initial_state: down
expected_state: up
- import_tasks: test_state.yml
vars:
state: unmonitored
initial_state: up
expected_state: down
- import_tasks: test_state.yml
vars:
state: monitored
initial_state: down
expected_state: up
- import_tasks: test_errors.yml

View file

@ -0,0 +1,6 @@
- name: Check an error occurs when wrong process name is used
monit:
name: missing
state: started
register: result
failed_when: result is not skip and (result is success or result is not failed)

View file

@ -0,0 +1,51 @@
- name: verify initial state (up)
command: "curl -sf http://localhost:8082/hello"
args:
warn: false
when: initial_state == 'up'
- name: verify initial state (down)
command: "curl -sf http://localhost:8082/hello"
args:
warn: false
register: curl_result
failed_when: curl_result == 0
when: initial_state == 'down'
- name: change httpd_echo process state to {{ state }}
monit:
name: httpd_echo
state: "{{ state }}"
register: result
- name: check that state changed
assert:
that:
- result is success
- result is changed
- name: check that service is {{ state }} (expected 'up')
command: "curl -sf http://localhost:8082/hello"
args:
warn: false
when: expected_state == 'up'
- name: check that service is {{ state }} (expected 'down')
command: "curl -sf http://localhost:8082/hello"
args:
warn: false
register: curl_result
failed_when: curl_result == 0
when: expected_state == 'down'
- name: try change state again to {{ state }}
monit:
name: httpd_echo
state: "{{ state }}"
register: result
- name: check that state is not changed
assert:
that:
- result is success
- result is not changed