Skip to content

Commit

Permalink
test: recode silence tests and add org tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemental committed May 27, 2024
1 parent 77d3bfa commit 4b0ddd9
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 87 deletions.
83 changes: 83 additions & 0 deletions tests/integration/targets/grafana_silence/tasks/create-delete.yml
Original file line number Diff line number Diff line change
@@ -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'"
91 changes: 4 additions & 87 deletions tests/integration/targets/grafana_silence/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -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'"
- name: Silence creation and deletion for organization
ansible.builtin.include_tasks: org.yml
7 changes: 7 additions & 0 deletions tests/integration/targets/grafana_silence/tasks/org.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4b0ddd9

Please sign in to comment.