From a1e4f826ca01cc409e5a0a171c68ce9ecf6952f4 Mon Sep 17 00:00:00 2001
From: Michael DeHaan <michael.dehaan@gmail.com>
Date: Sat, 26 Jul 2014 10:37:55 -0400
Subject: [PATCH] Add some more integration tests for the task and playbook include mechanism.

---
 test/integration/Makefile                                       |  5 ++++-
 test/integration/roles/test_includes/handlers/main.yml          |  2 ++
 test/integration/roles/test_includes/handlers/more_handlers.yml | 14 ++++++++++++++
 test/integration/roles/test_includes/tasks/included_task1.yml   | 10 ++++++++++
 test/integration/roles/test_includes/tasks/main.yml             | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 test/integration/roles/test_includes/tasks/not_a_role_task.yml  |  4 ++++
 test/integration/test_includes.yml                              |  1 +
 test/integration/test_includes2.yml                             | 13 +++++++++++++
 8 files changed, 120 insertions(+), 1 deletion(-)
 create mode 100644 test/integration/roles/test_includes/handlers/main.yml
 create mode 100644 test/integration/roles/test_includes/handlers/more_handlers.yml
 create mode 100644 test/integration/roles/test_includes/tasks/included_task1.yml
 create mode 100644 test/integration/roles/test_includes/tasks/main.yml
 create mode 100644 test/integration/roles/test_includes/tasks/not_a_role_task.yml
 create mode 100644 test/integration/test_includes.yml
 create mode 100644 test/integration/test_includes2.yml

diff --git a/test/integration/Makefile b/test/integration/Makefile
index 5b4cd4e..6df1b31 100644
--- a/test/integration/Makefile
+++ b/test/integration/Makefile
@@ -16,7 +16,7 @@ endif
 
 VAULT_PASSWORD_FILE = vault-password
 
-all: non_destructive destructive check_mode test_hash test_handlers test_group_by test_vault parsing
+all: non_destructive destructive includes check_mode test_hash test_handlers test_group_by test_vault parsing
 
 parsing:
 	ansible-playbook bad_parsing.yml -i $(INVENTORY) -e @$(VARS_FILE) $(CREDENTIALS_ARG) -vvv $(TEST_FLAGS) --tags common,scenario1; [ $$? -eq 3 ]
@@ -25,6 +25,9 @@ parsing:
 	ansible-playbook bad_parsing.yml -i $(INVENTORY) -e @$(VARS_FILE) $(CREDENTIALS_ARG) -vvv $(TEST_FLAGS) --tags common,scenario4; [ $$? -eq 3 ]
 	ansible-playbook good_parsing.yml -i $(INVENTORY) -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS)
 
+includes:
+	ansible-playbook test_includes.yml -i $(INVENTORY) -e @$(VARS_FILE) $(CREDENTIALS_ARG) $(TEST_FLAGS) 
+
 unicode:
 	ansible-playbook unicode.yml -i $(INVENTORY) -e @$(VARS_FILE) -v $(TEST_FLAGS)
 
diff --git a/test/integration/roles/test_includes/handlers/main.yml b/test/integration/roles/test_includes/handlers/main.yml
new file mode 100644
index 0000000..25e7d38
--- /dev/null
+++ b/test/integration/roles/test_includes/handlers/main.yml
@@ -0,0 +1,2 @@
+- include: more_handlers.yml
+
diff --git a/test/integration/roles/test_includes/handlers/more_handlers.yml b/test/integration/roles/test_includes/handlers/more_handlers.yml
new file mode 100644
index 0000000..947ede8
--- /dev/null
+++ b/test/integration/roles/test_includes/handlers/more_handlers.yml
@@ -0,0 +1,14 @@
+- name: included_handler
+  set_fact:
+    ca: 4001
+    cb: 4002
+    cc: 4003
+
+- name: verify_handler
+  assert:
+    that:
+      - "ca == 4001"
+      - "cb == 4002"
+      - "cc == 4003"
+
+
diff --git a/test/integration/roles/test_includes/tasks/included_task1.yml b/test/integration/roles/test_includes/tasks/included_task1.yml
new file mode 100644
index 0000000..835985a
--- /dev/null
+++ b/test/integration/roles/test_includes/tasks/included_task1.yml
@@ -0,0 +1,10 @@
+- set_fact: 
+    ca: "{{ a }}"
+
+- set_fact: 
+    cb: "{{b}}"
+
+- set_fact:
+    cc: "{{ c }}"
+
+
diff --git a/test/integration/roles/test_includes/tasks/main.yml b/test/integration/roles/test_includes/tasks/main.yml
new file mode 100644
index 0000000..7cf9283
--- /dev/null
+++ b/test/integration/roles/test_includes/tasks/main.yml
@@ -0,0 +1,72 @@
+# test code for the ping module
+# (c) 2014, James Cammarata <jcammarata@ansible.com>
+
+# This file is part of Ansible
+#
+# Ansible is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Ansible is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.
+
+
+- include: included_task1.yml a=1 b=2 c=3
+
+- name: verify non-variable include params
+  assert:
+    that:
+      - "ca == '1'"
+      - "cb == '2'"
+      - "cc == '3'"
+
+- set_fact: 
+     a: 101 
+     b: 102
+     c: 103
+
+- include: included_task1.yml a={{a}} b={{b}} c=103
+
+- name: verify variable include params
+  assert: 
+    that:
+      - "ca == '101'"
+      - "cb == '102'"
+      - "cc == '103'"
+
+# now try long form includes
+#
+# FIXME: not sure if folks were using this, or if vars were top level, but seems like
+# it should be a thing.
+#
+#- include: included_task1.yml
+#  vars:
+#    a: 201
+#    b: 202
+#    c: 203
+#
+#- debug: var=a
+#- debug: var=b
+#- debug: var=c
+#
+#- name: verify long-form include params
+#  assert: 
+#    that:
+#      - "ca == 201"
+#      - "cb == 202"
+#      - "cc == 203"
+
+- name: test handlers with includes
+  shell: echo 1
+  notify:
+    # both these via a handler include
+    - included_handler
+    - verify_handler
+
+
diff --git a/test/integration/roles/test_includes/tasks/not_a_role_task.yml b/test/integration/roles/test_includes/tasks/not_a_role_task.yml
new file mode 100644
index 0000000..862b051
--- /dev/null
+++ b/test/integration/roles/test_includes/tasks/not_a_role_task.yml
@@ -0,0 +1,4 @@
+- set_fact:
+    ca: 33000
+    cb: 33001
+    cc: 33002
diff --git a/test/integration/test_includes.yml b/test/integration/test_includes.yml
new file mode 100644
index 0000000..4061245
--- /dev/null
+++ b/test/integration/test_includes.yml
@@ -0,0 +1 @@
+- include: test_includes2.yml
diff --git a/test/integration/test_includes2.yml b/test/integration/test_includes2.yml
new file mode 100644
index 0000000..4b538dc
--- /dev/null
+++ b/test/integration/test_includes2.yml
@@ -0,0 +1,13 @@
+
+- hosts: testhost
+  gather_facts: True
+  roles: 
+    - { role: test_includes, tags: test_includes }
+  tasks:
+    - include: roles/test_includes/tasks/not_a_role_task.yml
+    - assert:
+        that:
+          - "ca == 33000"
+          - "cb == 33001"
+          - "cc == 33002"
+          
--
libgit2 0.26.0