diff --git a/changelogs/fragments/238_checkmode.yml b/changelogs/fragments/238_checkmode.yml new file mode 100644 index 00000000..81785b52 --- /dev/null +++ b/changelogs/fragments/238_checkmode.yml @@ -0,0 +1,2 @@ +trivial: + - run integration tests in check-mode. diff --git a/tests/integration/targets/grafana_dashboard/runme.sh b/tests/integration/targets/grafana_dashboard/runme.sh new file mode 100755 index 00000000..867afb0d --- /dev/null +++ b/tests/integration/targets/grafana_dashboard/runme.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -eux + +ansible-playbook site.yml diff --git a/tests/integration/targets/grafana_dashboard/site.yml b/tests/integration/targets/grafana_dashboard/site.yml new file mode 100644 index 00000000..c32364ef --- /dev/null +++ b/tests/integration/targets/grafana_dashboard/site.yml @@ -0,0 +1,6 @@ +--- +- name: Run tests for grafana_dashboard + hosts: localhost + tasks: + - ansible.builtin.include_role: + name: ../../grafana_dashboard diff --git a/tests/integration/targets/grafana_datasource/runme.sh b/tests/integration/targets/grafana_datasource/runme.sh new file mode 100755 index 00000000..867afb0d --- /dev/null +++ b/tests/integration/targets/grafana_datasource/runme.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -eux + +ansible-playbook site.yml diff --git a/tests/integration/targets/grafana_datasource/site.yml b/tests/integration/targets/grafana_datasource/site.yml new file mode 100644 index 00000000..c8374dcd --- /dev/null +++ b/tests/integration/targets/grafana_datasource/site.yml @@ -0,0 +1,6 @@ +--- +- name: Run tests for grafana_datasource + hosts: localhost + tasks: + - ansible.builtin.include_role: + name: ../../grafana_datasource diff --git a/tests/integration/targets/grafana_folder/runme.sh b/tests/integration/targets/grafana_folder/runme.sh new file mode 100755 index 00000000..9daa487d --- /dev/null +++ b/tests/integration/targets/grafana_folder/runme.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -eux + +ansible-playbook site.yml --check +ansible-playbook site.yml diff --git a/tests/integration/targets/grafana_folder/site.yml b/tests/integration/targets/grafana_folder/site.yml new file mode 100644 index 00000000..2041400e --- /dev/null +++ b/tests/integration/targets/grafana_folder/site.yml @@ -0,0 +1,6 @@ +--- +- name: Run tests for grafana_folder + hosts: localhost + tasks: + - ansible.builtin.include_role: + name: ../../grafana_folder diff --git a/tests/integration/targets/grafana_folder/tasks/main.yml b/tests/integration/targets/grafana_folder/tasks/main.yml index cada94ab..bee3dc50 100644 --- a/tests/integration/targets/grafana_folder/tasks/main.yml +++ b/tests/integration/targets/grafana_folder/tasks/main.yml @@ -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: @@ -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: @@ -39,6 +41,7 @@ - ansible.builtin.assert: that: - result.changed == true + when: not ansible_check_mode - name: Test folder deletion idempotency grafana_folder: @@ -52,3 +55,4 @@ - ansible.builtin.assert: that: - result.changed == false + when: not ansible_check_mode diff --git a/tests/integration/targets/grafana_notification_channel/runme.sh b/tests/integration/targets/grafana_notification_channel/runme.sh new file mode 100755 index 00000000..867afb0d --- /dev/null +++ b/tests/integration/targets/grafana_notification_channel/runme.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -eux + +ansible-playbook site.yml diff --git a/tests/integration/targets/grafana_notification_channel/site.yml b/tests/integration/targets/grafana_notification_channel/site.yml new file mode 100644 index 00000000..e20f44e3 --- /dev/null +++ b/tests/integration/targets/grafana_notification_channel/site.yml @@ -0,0 +1,6 @@ +--- +- name: Run tests for grafana_notification_channel + hosts: localhost + tasks: + - ansible.builtin.include_role: + name: ../../grafana_notification_channel diff --git a/tests/integration/targets/grafana_organization/runme.sh b/tests/integration/targets/grafana_organization/runme.sh new file mode 100755 index 00000000..9daa487d --- /dev/null +++ b/tests/integration/targets/grafana_organization/runme.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -eux + +ansible-playbook site.yml --check +ansible-playbook site.yml diff --git a/tests/integration/targets/grafana_organization/site.yml b/tests/integration/targets/grafana_organization/site.yml new file mode 100644 index 00000000..e2e4900b --- /dev/null +++ b/tests/integration/targets/grafana_organization/site.yml @@ -0,0 +1,6 @@ +--- +- name: Run tests for grafana_organization + hosts: localhost + tasks: + - ansible.builtin.include_role: + name: ../../grafana_organization diff --git a/tests/integration/targets/grafana_organization/tasks/main.yml b/tests/integration/targets/grafana_organization/tasks/main.yml index 156bc940..936b147c 100644 --- a/tests/integration/targets/grafana_organization/tasks/main.yml +++ b/tests/integration/targets/grafana_organization/tasks/main.yml @@ -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: @@ -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: @@ -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: @@ -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 diff --git a/tests/integration/targets/grafana_organization_user/runme.sh b/tests/integration/targets/grafana_organization_user/runme.sh new file mode 100755 index 00000000..9daa487d --- /dev/null +++ b/tests/integration/targets/grafana_organization_user/runme.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -eux + +ansible-playbook site.yml --check +ansible-playbook site.yml diff --git a/tests/integration/targets/grafana_organization_user/site.yml b/tests/integration/targets/grafana_organization_user/site.yml new file mode 100644 index 00000000..80e5ea91 --- /dev/null +++ b/tests/integration/targets/grafana_organization_user/site.yml @@ -0,0 +1,6 @@ +--- +- name: Run tests for grafana_organization_user + hosts: localhost + tasks: + - ansible.builtin.include_role: + name: ../../grafana_organization_user diff --git a/tests/integration/targets/grafana_organization_user/tasks/main.yml b/tests/integration/targets/grafana_organization_user/tasks/main.yml index 6887670c..73b0482a 100644 --- a/tests/integration/targets/grafana_organization_user/tasks/main.yml +++ b/tests/integration/targets/grafana_organization_user/tasks/main.yml @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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: @@ -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 diff --git a/tests/integration/targets/grafana_team/runme.sh b/tests/integration/targets/grafana_team/runme.sh new file mode 100755 index 00000000..867afb0d --- /dev/null +++ b/tests/integration/targets/grafana_team/runme.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +set -eux + +ansible-playbook site.yml diff --git a/tests/integration/targets/grafana_team/site.yml b/tests/integration/targets/grafana_team/site.yml new file mode 100644 index 00000000..c8a61889 --- /dev/null +++ b/tests/integration/targets/grafana_team/site.yml @@ -0,0 +1,6 @@ +--- +- name: Run tests for grafana_team + hosts: localhost + tasks: + - ansible.builtin.include_role: + name: ../../grafana_team diff --git a/tests/integration/targets/grafana_team/tasks/main.yml b/tests/integration/targets/grafana_team/tasks/main.yml index 74fb5c84..d43eb828 100644 --- a/tests/integration/targets/grafana_team/tasks/main.yml +++ b/tests/integration/targets/grafana_team/tasks/main.yml @@ -4,9 +4,10 @@ url: "{{ grafana_url }}" url_username: "{{ grafana_username }}" url_password: "{{ grafana_password }}" - name: grafana_working_group + name: grafana working group email: foo.bar@example.com state: present + skip_version_check: true register: result - ansible.builtin.set_fact: @@ -19,17 +20,18 @@ - ansible.builtin.assert: that: - result.changed == true - - result.team.name == 'grafana_working_group' + - result.team.name == 'grafana working group' - result.team.email == 'foo.bar@example.com' - result.team.memberCount == (expected_members|length) - result.team.members == expected_members + when: not ansible_check_mode - name: Check idempotency on team creation community.grafana.grafana_team: url: "{{ grafana_url }}" url_username: "{{ grafana_username }}" url_password: "{{ grafana_password }}" - name: grafana_working_group + name: grafana working group email: foo.bar@example.com state: present register: result @@ -37,17 +39,18 @@ - ansible.builtin.assert: that: - result.changed == false - - result.team.name == 'grafana_working_group' + - result.team.name == 'grafana working group' - result.team.email == 'foo.bar@example.com' - result.team.memberCount == (expected_members|length) - result.team.members == expected_members + when: not ansible_check_mode - name: Check a team can be deleted community.grafana.grafana_team: url: "{{ grafana_url }}" url_username: "{{ grafana_username }}" url_password: "{{ grafana_password }}" - name: grafana_working_group + name: grafana working group email: foo.bar@example.com state: absent register: result @@ -56,13 +59,14 @@ that: - result.changed == true - result.message == 'Team deleted' + when: not ansible_check_mode - name: Check idempotency on team deletion community.grafana.grafana_team: url: "{{ grafana_url }}" url_username: "{{ grafana_username }}" url_password: "{{ grafana_password }}" - name: grafana_working_group + name: grafana working group email: foo.bar@example.com state: absent register: result @@ -71,16 +75,18 @@ that: - result.changed == false - result.message == 'No team found' + when: not ansible_check_mode - name: Create users for tests purpose ansible.builtin.import_tasks: file: create_user.yml + - name: Create a Team with members community.grafana.grafana_team: url: "{{ grafana_url }}" url_username: "{{ grafana_username }}" url_password: "{{ grafana_password }}" - name: grafana_working_group + name: grafana working group email: foo.bar@example.com members: - john+doe@example.com @@ -95,17 +101,18 @@ - ansible.builtin.assert: that: - result.changed == true - - result.team.name == 'grafana_working_group' + - result.team.name == 'grafana working group' - result.team.email == 'foo.bar@example.com' - result.team.memberCount == (expected_members|length) - result.team.members == expected_members + when: not ansible_check_mode - name: Ensure a Team exists with member not enforced community.grafana.grafana_team: url: "{{ grafana_url }}" url_username: "{{ grafana_username }}" url_password: "{{ grafana_password }}" - name: grafana_working_group + name: grafana working group email: foo.bar@example.com members: - john+doe@example.com @@ -115,10 +122,11 @@ - ansible.builtin.assert: that: - result.changed == false - - result.team.name == 'grafana_working_group' + - result.team.name == 'grafana working group' - result.team.email == 'foo.bar@example.com' - result.team.memberCount == (expected_members|length) - result.team.members == expected_members + when: not ansible_check_mode - ansible.builtin.set_fact: enforced_members: "{{ auto_member | ternary(['admin@localhost', 'john+doe@example.com'], ['john+doe@example.com']) }}" @@ -129,7 +137,7 @@ url: "{{ grafana_url }}" url_username: "{{ grafana_username }}" url_password: "{{ grafana_password }}" - name: grafana_working_group + name: grafana working group email: foo.bar@example.com members: "{{ enforced_members }}" enforce_members: true @@ -139,7 +147,7 @@ - ansible.builtin.assert: that: - result.changed == true - - result.team.name == 'grafana_working_group' + - result.team.name == 'grafana working group' - result.team.email == 'foo.bar@example.com' - result.team.memberCount == (expected_members|length) - result.team.members == expected_members @@ -149,7 +157,7 @@ url: "{{ grafana_url }}" url_username: "{{ grafana_username }}" url_password: "{{ grafana_password }}" - name: grafana_working_group + name: grafana working group email: foo.bar@example.com state: present register: result @@ -157,17 +165,18 @@ - ansible.builtin.assert: that: - result.changed == false - - result.team.name == 'grafana_working_group' + - result.team.name == 'grafana working group' - result.team.email == 'foo.bar@example.com' - result.team.memberCount == (expected_members|length) - result.team.members == expected_members + when: not ansible_check_mode - name: Add new member to existing Team community.grafana.grafana_team: url: "{{ grafana_url }}" url_username: "{{ grafana_username }}" url_password: "{{ grafana_password }}" - name: grafana_working_group + name: grafana working group email: foo.bar@example.com members: - john+doe@example.com @@ -182,7 +191,8 @@ - ansible.builtin.assert: that: - result.changed == true - - result.team.name == 'grafana_working_group' + - result.team.name == 'grafana working group' - result.team.email == 'foo.bar@example.com' - result.team.memberCount == (expected_members|length) - result.team.members == expected_members + when: not ansible_check_mode diff --git a/tests/integration/targets/grafana_user/runme.sh b/tests/integration/targets/grafana_user/runme.sh new file mode 100755 index 00000000..9daa487d --- /dev/null +++ b/tests/integration/targets/grafana_user/runme.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +set -eux + +ansible-playbook site.yml --check +ansible-playbook site.yml diff --git a/tests/integration/targets/grafana_user/site.yml b/tests/integration/targets/grafana_user/site.yml new file mode 100644 index 00000000..b080803f --- /dev/null +++ b/tests/integration/targets/grafana_user/site.yml @@ -0,0 +1,6 @@ +--- +- name: Run tests for grafana_user + hosts: localhost + tasks: + - ansible.builtin.include_role: + name: ../../grafana_user diff --git a/tests/integration/targets/grafana_user/tasks/main.yml b/tests/integration/targets/grafana_user/tasks/main.yml index 01ded30b..83a3891e 100644 --- a/tests/integration/targets/grafana_user/tasks/main.yml +++ b/tests/integration/targets/grafana_user/tasks/main.yml @@ -18,6 +18,7 @@ - result.user.name == 'Harley Quinn' - result.user.email == 'harley.quinn@gotham.city' - result.user.isGrafanaAdmin == true + when: not ansible_check_mode - name: Check idempotency on admin creation community.grafana.grafana_user: @@ -37,6 +38,7 @@ - result.user.name == 'Harley Quinn' - result.user.email == 'harley.quinn@gotham.city' - result.user.isGrafanaAdmin == true + when: not ansible_check_mode - name: Check user creation with Grafana API ansible.builtin.uri: @@ -54,6 +56,7 @@ - result.json.name == 'Harley Quinn' - result.json.email == 'harley.quinn@gotham.city' - result.json.isGrafanaAdmin == true + when: not ansible_check_mode - name: Create a Grafana user without password (expect failure) community.grafana.grafana_user: @@ -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: @@ -89,6 +93,7 @@ - result.user.name == 'Bruce Wayne' - result.user.email == 'batman@gotham.city' - result.user.isGrafanaAdmin == false + when: not ansible_check_mode - name: Check idempotency on user creation (password not requiered) community.grafana.grafana_user: @@ -106,6 +111,7 @@ - result.user.name == 'Bruce Wayne' - result.user.email == 'batman@gotham.city' - result.user.isGrafanaAdmin == false + when: not ansible_check_mode - name: Check user creation with Grafana API ansible.builtin.uri: @@ -123,6 +129,7 @@ - result.json.name == 'Bruce Wayne' - result.json.email == 'batman@gotham.city' - result.json.isGrafanaAdmin == false + when: not ansible_check_mode - name: Update Grafana user community.grafana.grafana_user: @@ -142,6 +149,7 @@ - result.user.name == 'The Dark Knight' - result.user.email == 'thedarkknight@gotham.city' - result.user.isGrafanaAdmin == true + when: not ansible_check_mode - name: Check user update with Grafana API ansible.builtin.uri: @@ -159,6 +167,7 @@ - result.json.name == 'The Dark Knight' - result.json.email == 'thedarkknight@gotham.city' - result.json.isGrafanaAdmin == true + when: not ansible_check_mode - name: Delete a Grafana user community.grafana.grafana_user: @@ -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: @@ -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: @@ -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: @@ -218,6 +230,7 @@ - result.user.name == 'Bruce Wayne' - result.user.email == 'bruce+wayne@gotham.city' - result.user.isGrafanaAdmin == false + when: not ansible_check_mode - name: Check idempotency on user creation (password not requiered) community.grafana.grafana_user: @@ -235,3 +248,4 @@ - result.user.name == 'Bruce Wayne' - result.user.email == 'bruce+wayne@gotham.city' - result.user.isGrafanaAdmin == false + when: not ansible_check_mode