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.
(cherry picked from commit 987265a6ef
)
Co-authored-by: Sam Doran <sdoran@redhat.com>
This commit is contained in:
parent
7dad6ca149
commit
3a5bd5be18
6 changed files with 44 additions and 1 deletions
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- account for empty strings in when splitting the host pattern (https://github.com/ansible/ansible/issues/61964)
|
|
@ -130,7 +130,7 @@ def split_host_pattern(pattern):
|
|||
'''), pattern, re.X
|
||||
)
|
||||
|
||||
return [p.strip() for p in patterns]
|
||||
return [p.strip() for p in patterns if p.strip()]
|
||||
|
||||
|
||||
class InventoryManager(object):
|
||||
|
|
1
test/integration/targets/inventory_limit/aliases
Normal file
1
test/integration/targets/inventory_limit/aliases
Normal file
|
@ -0,0 +1 @@
|
|||
shippable/posix/group4
|
5
test/integration/targets/inventory_limit/hosts.yml
Normal file
5
test/integration/targets/inventory_limit/hosts.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
all:
|
||||
hosts:
|
||||
host1:
|
||||
host2:
|
||||
host3:
|
31
test/integration/targets/inventory_limit/runme.sh
Executable file
31
test/integration/targets/inventory_limit/runme.sh
Executable file
|
@ -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
|
||||
|
|
@ -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 = [
|
||||
|
|
Loading…
Reference in a new issue