summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael DeHaan <michael.dehaan@gmail.com>2014-07-23 22:10:58 -0400
committerJames Cammarata <jimi@sngx.net>2014-07-24 21:59:21 -0500
commitd0cb512798dca8415a8219cfb27ad5fbb9432d91 (patch)
tree46965270241acd1f3286aa2325ea70d2011060de
parentb2b04ad8cbe43674bc859a1d6cc6ef11f061dbe3 (diff)
downloadansible-d0cb512798dca8415a8219cfb27ad5fbb9432d91.tar.gz
Add a lot of tests to verify parsing routines for scenarios that should pass. Some changes TBD, like stripping command spaces off end of expressions.
-rw-r--r--test/integration/Makefile5
-rw-r--r--test/integration/all.yml2
-rw-r--r--test/integration/good_parsing.yml9
-rw-r--r--test/integration/roles/test_good_parsing/tasks/main.yml118
4 files changed, 132 insertions, 2 deletions
diff --git a/test/integration/Makefile b/test/integration/Makefile
index 19e087e75b..4edaa5b36e 100644
--- a/test/integration/Makefile
+++ b/test/integration/Makefile
@@ -14,7 +14,10 @@ else
CREDENTIALS_ARG =
endif
-all: non_destructive destructive check_mode test_hash test_handlers test_group_by
+all: non_destructive destructive check_mode test_hash test_handlers test_group_by parsing
+
+parsing:
+ ansible-playbook good_parsing.yml -i $(INVENTORY) -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS)
non_destructive:
ansible-playbook non_destructive.yml -i $(INVENTORY) -e @$(VARS_FILE) $(CREDENTIALS_ARG) -v $(TEST_FLAGS)
diff --git a/test/integration/all.yml b/test/integration/all.yml
index 7195dba161..d15fa32aa5 100644
--- a/test/integration/all.yml
+++ b/test/integration/all.yml
@@ -3,4 +3,4 @@
- include: destructive.yml
- include: rackspace.yml
- include: amazon.yml
-
+- include: good_parsing.yml
diff --git a/test/integration/good_parsing.yml b/test/integration/good_parsing.yml
new file mode 100644
index 0000000000..8fc8d88ec9
--- /dev/null
+++ b/test/integration/good_parsing.yml
@@ -0,0 +1,9 @@
+- hosts: testhost
+
+ # the following commands should all parse fine and execute fine
+ # and represent quoting scenarios that should be legit
+
+ gather_facts: False
+
+ roles:
+ - { role: test_good_parsing, tags: test_good_parsing }
diff --git a/test/integration/roles/test_good_parsing/tasks/main.yml b/test/integration/roles/test_good_parsing/tasks/main.yml
new file mode 100644
index 0000000000..2e97bb2cf9
--- /dev/null
+++ b/test/integration/roles/test_good_parsing/tasks/main.yml
@@ -0,0 +1,118 @@
+# test code for the ping module
+# (c) 2014, Michael DeHaan <michael@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/>.
+
+# various tests of things that should not cause parsing problems
+
+- set_fact:
+ test_input: "a=1 a=2 a=3"
+
+- set_fact:
+ multi_line: |
+ echo old
+ echo mcdonald
+ echo had
+ echo a
+ echo farm
+
+- shell: echo "dog"
+ register: result
+
+- assert:
+ that:
+ result.cmd == 'echo "dog" '
+
+- shell: echo 'dog'
+ register: result
+
+- assert:
+ that:
+ result.cmd == 'echo \'dog\' '
+
+- name: a quoted argument is not sent to the shell module as anything but a string parameter
+ shell: echo 'dog' 'executable=/usr/bin/python'
+ register: result
+
+- debug: var=result.cmd
+
+- assert:
+ that:
+ result.cmd == "echo 'dog' 'executable=/usr/bin/python' "
+
+- name: it is valid to pass multiple key=value arguments because the shell doesn't check key=value arguments
+ shell: echo quackquack=here quackquack=everywhere
+ register: result
+
+- assert:
+ that:
+ result.cmd == 'echo quackquack=here quackquack=everywhere '
+
+- name: the same is true with quoting
+ shell: echo "quackquack=here quackquack=everywhere"
+ register: result
+
+- assert:
+ that:
+ result.cmd == 'echo "quackquack=here quackquack=everywhere" '
+
+- name: the same is true with quoting (B)
+ shell: echo "quackquack=here" "quackquack=everywhere"
+ register: result
+
+- name: the same is true with quoting (C)
+ shell: echo "quackquack=here" 'quackquack=everywhere'
+ register: result
+
+- name: the same is true with quoting (D)
+ shell: echo "quackquack=here" 'quackquack=everywhere'
+ register: result
+
+- name: the same is true with quoting (E)
+ shell: echo {{ test_input }}
+ register: result
+
+- assert:
+ that:
+ result.cmd == "echo a=1 a=2 a=3 "
+
+- name: more shell duplicates
+ shell: echo foo=bar foo=bar
+ register: result
+
+- assert:
+ that:
+ result.cmd == "echo foo=bar foo=bar "
+
+- name: multi-line inline shell commands (should use script module but hey) are a thing
+ shell: "{{ multi_line }}"
+ register: result
+
+- debug: var=result
+
+- assert:
+ that:
+ result.stdout_lines == [ 'old', 'mcdonald', 'had', 'a', 'farm' ]
+
+- name: passing same arg to shell command is legit
+ shell: echo foo --arg=a --arg=b
+ failed_when: False # just catch the exit code, parse error is what I care about, but should register and compare result
+ register: result
+
+- assert:
+ that:
+ # command shouldn't end in spaces, amend test once fixed
+ - result.cmd == "echo foo --arg=a --arg=b "