From d74ccea44f19910603c8060103d0d5bd89ddd739 Mon Sep 17 00:00:00 2001
From: Martin Krizek <martin.krizek@gmail.com>
Date: Mon, 21 May 2018 07:48:40 +0200
Subject: [PATCH] rabbitmq_vhost: add integration tests (#40387)

* rabbitmq_vhost: add integration tests

* Use import_tasks instead of include
---
 .../targets/rabbitmq_vhost/aliases            |   5 +
 .../targets/rabbitmq_vhost/meta/main.yml      |   2 +
 .../targets/rabbitmq_vhost/tasks/main.yml     |   2 +
 .../targets/rabbitmq_vhost/tasks/tests.yml    | 121 ++++++++++++++++++
 4 files changed, 130 insertions(+)
 create mode 100644 test/integration/targets/rabbitmq_vhost/aliases
 create mode 100644 test/integration/targets/rabbitmq_vhost/meta/main.yml
 create mode 100644 test/integration/targets/rabbitmq_vhost/tasks/main.yml
 create mode 100644 test/integration/targets/rabbitmq_vhost/tasks/tests.yml

diff --git a/test/integration/targets/rabbitmq_vhost/aliases b/test/integration/targets/rabbitmq_vhost/aliases
new file mode 100644
index 00000000000..c9a649c10c2
--- /dev/null
+++ b/test/integration/targets/rabbitmq_vhost/aliases
@@ -0,0 +1,5 @@
+destructive
+posix/ci/group1
+skip/osx
+skip/freebsd
+skip/rhel
diff --git a/test/integration/targets/rabbitmq_vhost/meta/main.yml b/test/integration/targets/rabbitmq_vhost/meta/main.yml
new file mode 100644
index 00000000000..05ab59000bb
--- /dev/null
+++ b/test/integration/targets/rabbitmq_vhost/meta/main.yml
@@ -0,0 +1,2 @@
+dependencies:
+  - setup_rabbitmq
diff --git a/test/integration/targets/rabbitmq_vhost/tasks/main.yml b/test/integration/targets/rabbitmq_vhost/tasks/main.yml
new file mode 100644
index 00000000000..593906fb745
--- /dev/null
+++ b/test/integration/targets/rabbitmq_vhost/tasks/main.yml
@@ -0,0 +1,2 @@
+- import_tasks: tests.yml
+  when: ansible_distribution == 'Ubuntu'
diff --git a/test/integration/targets/rabbitmq_vhost/tasks/tests.yml b/test/integration/targets/rabbitmq_vhost/tasks/tests.yml
new file mode 100644
index 00000000000..019c5edee63
--- /dev/null
+++ b/test/integration/targets/rabbitmq_vhost/tasks/tests.yml
@@ -0,0 +1,121 @@
+- block:
+  - set_fact:
+      vhost_name: /test
+
+  - name: Add host
+    rabbitmq_vhost:
+      name: "{{ vhost_name }}"
+      state: present
+    register: result
+
+  - name: Check that the host was created successfuly
+    shell: "rabbitmqctl list_vhosts name tracing | grep {{ vhost_name }}"
+    register: ctl_result
+
+  - name: Check that the host is added
+    assert:
+      that:
+        - result is changed
+        - result is success
+        - '"false" in ctl_result.stdout'  # value for tracing, false is disabled
+
+  - name: Add host (idempotency)
+    rabbitmq_vhost:
+      name: "{{ vhost_name }}"
+      state: present
+    register: result
+
+  - name: Check idempotency
+    assert:
+      that:
+        - result is not changed
+
+  - name: Enable tracing
+    rabbitmq_vhost:
+      name: "{{ vhost_name }}"
+      tracing: yes
+    register: result
+
+  - name: Get rabbitmqctl output
+    shell: "rabbitmqctl list_vhosts name tracing | grep {{ vhost_name }}"
+    register: ctl_result
+
+  - name: Check that tracing is enabled
+    assert:
+      that:
+        - result is changed
+        - result is success
+        - '"true" in ctl_result.stdout'  # value for tracing, true is enabled
+
+  - name: Enable tracing (idempotency)
+    rabbitmq_vhost:
+      name: "{{ vhost_name }}"
+      tracing: yes
+    register: result
+
+  - name: Check idempotency
+    assert:
+      that:
+        - result is not changed
+
+  - name: Disable tracing
+    rabbitmq_vhost:
+      name: "{{ vhost_name }}"
+      tracing: no
+    register: result
+
+  - name: Get rabbitmqctl output
+    shell: "rabbitmqctl list_vhosts name tracing | grep {{ vhost_name }}"
+    register: ctl_result
+
+  - name: Check that tracing is disabled
+    assert:
+      that:
+        - result is changed
+        - result is success
+        - '"false" in ctl_result.stdout'  # value for tracing, false is disabled
+
+  - name: Disable tracing (idempotency)
+    rabbitmq_vhost:
+      name: "{{ vhost_name }}"
+      tracing: no
+    register: result
+
+  - name: Check idempotency
+    assert:
+      that:
+        - result is not changed
+
+  - name: Remove host
+    rabbitmq_vhost:
+      name: "{{ vhost_name }}"
+      state: absent
+    register: result
+
+  - name: Get rabbitmqctl output
+    shell: "rabbitmqctl list_vhosts name tracing | grep {{ vhost_name }}"
+    register: ctl_result
+    failed_when: ctl_result.rc == 0
+
+  - name: Check that the host is removed
+    assert:
+      that:
+        - result is changed
+        - result is success
+
+  - name: Remove host (idempotency)
+    rabbitmq_vhost:
+      name: "{{ vhost_name }}"
+      state: absent
+    register: result
+
+  - name: Check idempotency
+    assert:
+      that:
+        - result is not changed
+
+  always:
+    - name: Remove host
+      rabbitmq_vhost:
+        name: "{{ vhost_name }}"
+        state: absent