Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try run tests in check-mode, too #328

Merged
merged 6 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/238_checkmode.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
trivial:
- run integration tests in check-mode.
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
name: orgtest
state: present
register: result

- ansible.builtin.assert:
that:
- 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 @@ -21,11 +23,13 @@
name: orgtest
state: present
register: result

- ansible.builtin.assert:
that:
- 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 @@ -35,11 +39,13 @@
name: orgtest
state: absent
register: result

- ansible.builtin.assert:
that:
- 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 @@ -49,8 +55,10 @@
name: orgtest
state: absent
register: result

- ansible.builtin.assert:
that:
- result.changed == false
- result.failed == false
- result.msg == 'No org found, nothing to do'
when: not ansible_check_mode
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
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
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,15 @@
role: admin
state: present
register: result
when: not ansible_check_mode

- 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 @@ -118,10 +126,13 @@
login: orgtest
state: absent
register: result
when: not ansible_check_mode

- ansible.builtin.assert:
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 @@ -133,12 +144,15 @@
role: admin
state: present
register: result
when: not ansible_check_mode

- 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_name
community.grafana.grafana_organization_user:
Expand All @@ -149,7 +163,10 @@
login: orgtest
state: absent
register: result
when: not ansible_check_mode

- ansible.builtin.assert:
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
Loading
Loading