Skip to content

Commit

Permalink
try run tests in check-mode, too
Browse files Browse the repository at this point in the history
when a runme.sh exists in the test-path, it will be run. then the roles will be run in check-mode and normal-mode to test if they work in check mode (at least somewhat)
  • Loading branch information
rndmh3ro committed Jan 4, 2024
1 parent 0aedf86 commit 9c27779
Show file tree
Hide file tree
Showing 21 changed files with 128 additions and 9 deletions.
5 changes: 5 additions & 0 deletions tests/integration/targets/grafana_dashboard/runme.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -eux

ansible-playbook site.yml
6 changes: 6 additions & 0 deletions tests/integration/targets/grafana_dashboard/site.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Run tests for grafana_dashboard
hosts: localhost
tasks:
- ansible.builtin.include_role:
name: ../../grafana_dashboard
5 changes: 5 additions & 0 deletions tests/integration/targets/grafana_datasource/runme.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -eux

ansible-playbook site.yml
6 changes: 6 additions & 0 deletions tests/integration/targets/grafana_datasource/site.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Run tests for grafana_datasource
hosts: localhost
tasks:
- ansible.builtin.include_role:
name: ../../grafana_datasource
6 changes: 6 additions & 0 deletions tests/integration/targets/grafana_folder/runme.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

set -eux

ansible-playbook site.yml --check
ansible-playbook site.yml
6 changes: 6 additions & 0 deletions tests/integration/targets/grafana_folder/site.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Run tests for grafana_folder
hosts: localhost
tasks:
- ansible.builtin.include_role:
name: ../../grafana_folder
4 changes: 4 additions & 0 deletions tests/integration/targets/grafana_folder/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
that:
- result.changed == true
- result.folder.title == 'grafana_working_group'
when: not ansible_check_mode

- name: Test folder creation idempotency
grafana_folder:
Expand All @@ -26,6 +27,7 @@
that:
- result.changed == false
- result.folder.title == 'grafana_working_group'
when: not ansible_check_mode

- name: Delete a Folder
grafana_folder:
Expand All @@ -39,6 +41,7 @@
- ansible.builtin.assert:
that:
- result.changed == true
when: not ansible_check_mode

- name: Test folder deletion idempotency
grafana_folder:
Expand All @@ -52,3 +55,4 @@
- ansible.builtin.assert:
that:
- result.changed == false
when: not ansible_check_mode
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -eux

ansible-playbook site.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Run tests for grafana_notification_channel
hosts: localhost
tasks:
- ansible.builtin.include_role:
name: ../../grafana_notification_channel
6 changes: 6 additions & 0 deletions tests/integration/targets/grafana_organization/runme.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

set -eux

ansible-playbook site.yml --check
ansible-playbook site.yml
6 changes: 6 additions & 0 deletions tests/integration/targets/grafana_organization/site.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Run tests for grafana_organization
hosts: localhost
tasks:
- ansible.builtin.include_role:
name: ../../grafana_organization
11 changes: 5 additions & 6 deletions tests/integration/targets/grafana_organization/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@
url_password: "{{ grafana_password }}"
name: orgtest
state: present
register: result
- ansible.builtin.assert:
that:
- result.changed == true
- result.failed == false
- result.org.name == 'orgtest'
register: result - "result.changed == true" - "result.failed == false" - "result.org.name == 'orgtest'"
when: not ansible_check_mode

- name: Check idempotency Grafana organization
community.grafana.grafana_organization:
Expand All @@ -26,6 +22,7 @@
- result.changed == false
- result.failed == false
- result.org.name == 'orgtest'
when: not ansible_check_mode

- name: Delete a Grafana organization
community.grafana.grafana_organization:
Expand All @@ -40,6 +37,7 @@
- result.changed == true
- result.failed == false
- result.msg |length > 0
when: not ansible_check_mode

- name: Check idempotency delete a Grafana organization
community.grafana.grafana_organization:
Expand All @@ -54,3 +52,4 @@
- result.changed == false
- result.failed == false
- result.msg == 'No org found, nothing to do'
when: not ansible_check_mode
6 changes: 6 additions & 0 deletions tests/integration/targets/grafana_organization_user/runme.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

set -eux

ansible-playbook site.yml --check
ansible-playbook site.yml
6 changes: 6 additions & 0 deletions tests/integration/targets/grafana_organization_user/site.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Run tests for grafana_organization_user
hosts: localhost
tasks:
- ansible.builtin.include_role:
name: ../../grafana_organization_user
10 changes: 10 additions & 0 deletions tests/integration/targets/grafana_organization_user/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
that:
- result.failed == false
- result.changed == true
when: not ansible_check_mode

- name: Check idempotency on user removal from org
community.grafana.grafana_organization_user:
Expand All @@ -36,6 +37,7 @@
that:
- result.failed == false
- result.changed == false
when: not ansible_check_mode

- name: Add user to organization
community.grafana.grafana_organization_user:
Expand All @@ -52,6 +54,7 @@
- result.changed == true
- result.user.orgId == 1
- result.user.role == 'Viewer'
when: not ansible_check_mode

- name: Update existing user role
community.grafana.grafana_organization_user:
Expand All @@ -68,6 +71,7 @@
- result.changed == true
- result.user.orgId == 1
- result.user.role == 'Editor'
when: not ansible_check_mode

- name: Check idempotency on user update
community.grafana.grafana_organization_user:
Expand All @@ -82,6 +86,7 @@
that:
- result.failed == false
- result.changed == false
when: not ansible_check_mode

- name: Create a new organization
community.grafana.grafana_organization:
Expand All @@ -102,12 +107,14 @@
role: admin
state: present
register: result
- ansible.builtin.assert:
- ansible.builtin.assert:
that:
- result.failed == false
- result.changed == true
- result.user.orgId == org.org.id
- result.user.role == 'Admin'
when: not ansible_check_mode

- name: Remove user from new organization by org_id
community.grafana.grafana_organization_user:
Expand All @@ -122,6 +129,7 @@
that:
- result.failed == false
- result.changed == true
when: not ansible_check_mode

- name: Add user to the new organization by org_name
community.grafana.grafana_organization_user:
Expand All @@ -139,6 +147,7 @@
- result.changed == true
- result.user.orgId == org.org.id
- result.user.role == 'Admin'
when: not ansible_check_mode

- name: Remove user from new organization by org_name
community.grafana.grafana_organization_user:
Expand All @@ -153,3 +162,4 @@
that:
- result.failed == false
- result.changed == true
when: not ansible_check_mode
5 changes: 5 additions & 0 deletions tests/integration/targets/grafana_team/runme.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -eux

ansible-playbook site.yml
6 changes: 6 additions & 0 deletions tests/integration/targets/grafana_team/site.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Run tests for grafana_team
hosts: localhost
tasks:
- ansible.builtin.include_role:
name: ../../grafana_team
6 changes: 3 additions & 3 deletions tests/integration/targets/grafana_team/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
url: "{{ grafana_url }}"
url_username: "{{ grafana_username }}"
url_password: "{{ grafana_password }}"
name: grafana_working_group
name: grafana working group
email: [email protected]
state: present
skip_version_check: true
register: result

- ansible.builtin.set_fact:
Expand All @@ -19,7 +20,7 @@
- ansible.builtin.assert:
that:
- result.changed == true
- result.team.name == 'grafana_working_group'
- result.team.name == 'grafana working group'
- result.team.email == '[email protected]'
- result.team.memberCount == (expected_members|length)
- result.team.members == expected_members
Expand Down Expand Up @@ -173,7 +174,6 @@
- [email protected]
- [email protected]
state: present
register: result

- ansible.builtin.set_fact:
expected_members: "{{ auto_member | ternary(['********@localhost', '[email protected]', '[email protected]'], ['[email protected]', '[email protected]'])
Expand Down
6 changes: 6 additions & 0 deletions tests/integration/targets/grafana_user/runme.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

set -eux

ansible-playbook site.yml --check
ansible-playbook site.yml
6 changes: 6 additions & 0 deletions tests/integration/targets/grafana_user/site.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Run tests for grafana_user
hosts: localhost
tasks:
- ansible.builtin.include_role:
name: ../../grafana_user
14 changes: 14 additions & 0 deletions tests/integration/targets/grafana_user/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- result.user.name == 'Harley Quinn'
- result.user.email == '[email protected]'
- result.user.isGrafanaAdmin == true
when: not ansible_check_mode

- name: Check idempotency on admin creation
community.grafana.grafana_user:
Expand All @@ -37,6 +38,7 @@
- result.user.name == 'Harley Quinn'
- result.user.email == '[email protected]'
- result.user.isGrafanaAdmin == true
when: not ansible_check_mode

- name: Check user creation with Grafana API
ansible.builtin.uri:
Expand All @@ -54,6 +56,7 @@
- result.json.name == 'Harley Quinn'
- result.json.email == '[email protected]'
- result.json.isGrafanaAdmin == true
when: not ansible_check_mode

- name: Create a Grafana user without password (expect failure)
community.grafana.grafana_user:
Expand All @@ -71,6 +74,7 @@
- result.changed == false
- result.failed == true
- "result.msg == 'missing required arguments: password'"
when: not ansible_check_mode

- name: Create a Grafana user
community.grafana.grafana_user:
Expand All @@ -89,6 +93,7 @@
- result.user.name == 'Bruce Wayne'
- result.user.email == '[email protected]'
- result.user.isGrafanaAdmin == false
when: not ansible_check_mode

- name: Check idempotency on user creation (password not requiered)
community.grafana.grafana_user:
Expand All @@ -106,6 +111,7 @@
- result.user.name == 'Bruce Wayne'
- result.user.email == '[email protected]'
- result.user.isGrafanaAdmin == false
when: not ansible_check_mode

- name: Check user creation with Grafana API
ansible.builtin.uri:
Expand All @@ -123,6 +129,7 @@
- result.json.name == 'Bruce Wayne'
- result.json.email == '[email protected]'
- result.json.isGrafanaAdmin == false
when: not ansible_check_mode

- name: Update Grafana user
community.grafana.grafana_user:
Expand All @@ -142,6 +149,7 @@
- result.user.name == 'The Dark Knight'
- result.user.email == '[email protected]'
- result.user.isGrafanaAdmin == true
when: not ansible_check_mode

- name: Check user update with Grafana API
ansible.builtin.uri:
Expand All @@ -159,6 +167,7 @@
- result.json.name == 'The Dark Knight'
- result.json.email == '[email protected]'
- result.json.isGrafanaAdmin == true
when: not ansible_check_mode

- name: Delete a Grafana user
community.grafana.grafana_user:
Expand All @@ -172,6 +181,7 @@
that:
- result.changed == true
- result.message == 'User deleted'
when: not ansible_check_mode

- name: Check idempotency on user deletion
community.grafana.grafana_user:
Expand All @@ -185,6 +195,7 @@
that:
- result.changed == false
- result.message == 'No user found, nothing to do'
when: not ansible_check_mode

- name: Check user deletion with Grafana API (expect 404 Not Found)
ansible.builtin.uri:
Expand All @@ -200,6 +211,7 @@
- ansible.builtin.assert:
that:
- result.json.message | lower == 'user not found'
when: not ansible_check_mode

- name: Create a Grafana user with character encoding
community.grafana.grafana_user:
Expand All @@ -218,6 +230,7 @@
- result.user.name == 'Bruce Wayne'
- result.user.email == '[email protected]'
- result.user.isGrafanaAdmin == false
when: not ansible_check_mode

- name: Check idempotency on user creation (password not requiered)
community.grafana.grafana_user:
Expand All @@ -235,3 +248,4 @@
- result.user.name == 'Bruce Wayne'
- result.user.email == '[email protected]'
- result.user.isGrafanaAdmin == false
when: not ansible_check_mode

0 comments on commit 9c27779

Please sign in to comment.