diff --git a/tests/integration/targets/grafana_silence/tasks/create-delete.yml b/tests/integration/targets/grafana_silence/tasks/create-delete.yml new file mode 100644 index 00000000..1561eb59 --- /dev/null +++ b/tests/integration/targets/grafana_silence/tasks/create-delete.yml @@ -0,0 +1,83 @@ +--- +- module_defaults: + community.grafana.grafana_silence: + url: "{{ grafana_url }}" + url_username: "{{ grafana_username }}" + url_password: "{{ grafana_password }}" + block: + - name: Create new silence + community.grafana.grafana_silence: + comment: "a testcomment" + created_by: "me" + starts_at: "2029-07-29T08:45:45.000Z" + ends_at: "2029-07-29T08:55:45.000Z" + matchers: + - isEqual: true + isRegex: true + name: environment + value: test + state: present + register: result + - assert: + that: + - "result.changed == true" + - "result.failed == false" + - "result.silence.id != ''" + + - name: Check idempotency on silence creation + community.grafana.grafana_silence: + comment: "a testcomment" + created_by: "me" + starts_at: "2029-07-29T08:45:45.000Z" + ends_at: "2029-07-29T08:55:45.000Z" + matchers: + - isEqual: true + isRegex: true + name: environment + value: test + state: present + register: result + - assert: + that: + - "result.changed == false" + - "result.msg != ''" + + - name: Delete the silence + community.grafana.grafana_silence: + comment: "a testcomment" + created_by: "me" + starts_at: "2029-07-29T08:45:45.000Z" + ends_at: "2029-07-29T08:55:45.000Z" + matchers: + - isEqual: true + isRegex: true + name: environment + value: test + state: absent + register: result + - assert: + that: + - "result.changed == true" + - "result.failed == false" + - "result.silence.id != ''" + - - "result.silence.createdBy != 'me'" + + - name: Check idempotency on silence deletion + community.grafana.grafana_silence: + comment: "a testcomment" + created_by: "me" + starts_at: "2029-07-29T08:45:45.000Z" + ends_at: "2029-07-29T08:55:45.000Z" + matchers: + - isEqual: true + isRegex: true + name: environment + value: test + state: absent + register: result + ignore_errors: yes + - assert: + that: + - "result.changed == false" + - "result.failed == false" + - "result.msg == 'Silence does not exist'" diff --git a/tests/integration/targets/grafana_silence/tasks/main.yml b/tests/integration/targets/grafana_silence/tasks/main.yml index ad4cfa25..f8756077 100644 --- a/tests/integration/targets/grafana_silence/tasks/main.yml +++ b/tests/integration/targets/grafana_silence/tasks/main.yml @@ -1,89 +1,6 @@ --- -- name: Create new silence - community.grafana.grafana_silence: - url: "{{ grafana_url }}" - url_username: "{{ grafana_username }}" - url_password: "{{ grafana_password }}" - comment: "a testcomment" - created_by: "me" - starts_at: "2029-07-29T08:45:45.000Z" - ends_at: "2029-07-29T08:55:45.000Z" - matchers: - - isEqual: true - isRegex: true - name: environment - value: test - state: present - register: result -- assert: - that: - - "result.changed == true" - - "result.failed == false" - - "result.silence.id != ''" +- name: Silence creation and deletion + ansible.builtin.include_tasks: create-delete.yml -- name: Check idempotency on silence creation - community.grafana.grafana_silence: - url: "{{ grafana_url }}" - url_username: "{{ grafana_username }}" - url_password: "{{ grafana_password }}" - comment: "a testcomment" - created_by: "me" - starts_at: "2029-07-29T08:45:45.000Z" - ends_at: "2029-07-29T08:55:45.000Z" - matchers: - - isEqual: true - isRegex: true - name: environment - value: test - state: present - register: result -- assert: - that: - - "result.changed == false" - - "result.msg != ''" - -- name: Delete the silence - community.grafana.grafana_silence: - url: "{{ grafana_url }}" - url_username: "{{ grafana_username }}" - url_password: "{{ grafana_password }}" - comment: "a testcomment" - created_by: "me" - starts_at: "2029-07-29T08:45:45.000Z" - ends_at: "2029-07-29T08:55:45.000Z" - matchers: - - isEqual: true - isRegex: true - name: environment - value: test - state: absent - register: result -- assert: - that: - - "result.changed == true" - - "result.failed == false" - - "result.silence.id != ''" - - - "result.silence.createdBy != 'me'" - -- name: Check idempotency on silence deletion - community.grafana.grafana_silence: - url: "{{ grafana_url }}" - url_username: "{{ grafana_username }}" - url_password: "{{ grafana_password }}" - comment: "a testcomment" - created_by: "me" - starts_at: "2029-07-29T08:45:45.000Z" - ends_at: "2029-07-29T08:55:45.000Z" - matchers: - - isEqual: true - isRegex: true - name: environment - value: test - state: absent - register: result - ignore_errors: yes -- assert: - that: - - "result.changed == false" - - "result.failed == false" - - "result.msg == 'Silence does not exist'" \ No newline at end of file +- name: Silence creation and deletion for organization + ansible.builtin.include_tasks: org.yml diff --git a/tests/integration/targets/grafana_silence/tasks/org.yml b/tests/integration/targets/grafana_silence/tasks/org.yml new file mode 100644 index 00000000..514232f9 --- /dev/null +++ b/tests/integration/targets/grafana_silence/tasks/org.yml @@ -0,0 +1,7 @@ +--- +- module_defaults: + community.grafana.grafana_silence: + org_name: Main Org. + block: + - name: Silence creation and deletion + ansible.builtin.include_tasks: create-delete.yml