summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorSam Doran <sdoran@redhat.com>2019-09-20 22:03:51 +0200
committerGitHub <noreply@github.com>2019-09-20 22:03:51 +0200
commit987265a6ef920466b44625097ff85f3e845dc8ea (patch)
treede0ee35897219f38e25190a59e57b267a7110fd4 /test
parentallow before/after diff to be NoneType (#62582) (diff)
downloadansible-987265a6ef920466b44625097ff85f3e845dc8ea.tar.xz
ansible-987265a6ef920466b44625097ff85f3e845dc8ea.zip
Account for empty strings when splitting the host pattern (#62442)
Improve tests - add more unit test cases - add specific integration test with more cases Testing shows no major downside to calling .strip() twice in a comprehension vs. using a regular for loop and only calling .strip() once. Going with the comprehension for ease of maintenance and because comprehensions are optimized in CPython.
Diffstat (limited to 'test')
-rw-r--r--test/integration/targets/inventory_limit/aliases1
-rw-r--r--test/integration/targets/inventory_limit/hosts.yml5
-rwxr-xr-xtest/integration/targets/inventory_limit/runme.sh31
-rw-r--r--test/units/plugins/inventory/test_inventory.py4
4 files changed, 41 insertions, 0 deletions
diff --git a/test/integration/targets/inventory_limit/aliases b/test/integration/targets/inventory_limit/aliases
new file mode 100644
index 0000000000..3005e4b26d
--- /dev/null
+++ b/test/integration/targets/inventory_limit/aliases
@@ -0,0 +1 @@
+shippable/posix/group4
diff --git a/test/integration/targets/inventory_limit/hosts.yml b/test/integration/targets/inventory_limit/hosts.yml
new file mode 100644
index 0000000000..2e1b192730
--- /dev/null
+++ b/test/integration/targets/inventory_limit/hosts.yml
@@ -0,0 +1,5 @@
+all:
+ hosts:
+ host1:
+ host2:
+ host3:
diff --git a/test/integration/targets/inventory_limit/runme.sh b/test/integration/targets/inventory_limit/runme.sh
new file mode 100755
index 0000000000..6a142b3b1e
--- /dev/null
+++ b/test/integration/targets/inventory_limit/runme.sh
@@ -0,0 +1,31 @@
+#!/usr/bin/env bash
+
+set -eux
+
+trap 'echo "Host pattern limit test failed"' ERR
+
+# https://github.com/ansible/ansible/issues/61964
+
+# These tests should return all hosts
+ansible -i hosts.yml all --limit ,, --list-hosts | tee out ; grep -q 'hosts (3)' out
+ansible -i hosts.yml ,, --list-hosts | tee out ; grep -q 'hosts (3)' out
+ansible -i hosts.yml , --list-hosts | tee out ; grep -q 'hosts (3)' out
+ansible -i hosts.yml all --limit , --list-hosts | tee out ; grep -q 'hosts (3)' out
+ansible -i hosts.yml all --limit '' --list-hosts | tee out ; grep -q 'hosts (3)' out
+
+
+# Only one host
+ansible -i hosts.yml all --limit ,,host1 --list-hosts | tee out ; grep -q 'hosts (1)' out
+ansible -i hosts.yml ,,host1 --list-hosts | tee out ; grep -q 'hosts (1)' out
+
+ansible -i hosts.yml all --limit host1,, --list-hosts | tee out ; grep -q 'hosts (1)' out
+ansible -i hosts.yml host1,, --list-hosts | tee out ; grep -q 'hosts (1)' out
+
+
+# Only two hosts
+ansible -i hosts.yml all --limit host1,,host3 --list-hosts | tee out ; grep -q 'hosts (2)' out
+ansible -i hosts.yml host1,,host3 --list-hosts | tee out ; grep -q 'hosts (2)' out
+
+ansible -i hosts.yml all --limit 'host1, , ,host3' --list-hosts | tee out ; grep -q 'hosts (2)' out
+ansible -i hosts.yml 'host1, , ,host3' --list-hosts | tee out ; grep -q 'hosts (2)' out
+
diff --git a/test/units/plugins/inventory/test_inventory.py b/test/units/plugins/inventory/test_inventory.py
index 48c3f9834a..66b5ec3787 100644
--- a/test/units/plugins/inventory/test_inventory.py
+++ b/test/units/plugins/inventory/test_inventory.py
@@ -49,6 +49,10 @@ class TestInventory(unittest.TestCase):
'a:b': ['a', 'b'],
' a : b ': ['a', 'b'],
'foo:bar:baz[1:2]': ['foo', 'bar', 'baz[1:2]'],
+ 'a,,b': ['a', 'b'],
+ 'a, ,b,,c, ,': ['a', 'b', 'c'],
+ ',': [],
+ '': [],
}
pattern_lists = [