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>
0 | 5 |
new file mode 100755 |
... | ... |
@@ -0,0 +1,31 @@ |
0 |
+#!/usr/bin/env bash |
|
1 |
+ |
|
2 |
+set -eux |
|
3 |
+ |
|
4 |
+trap 'echo "Host pattern limit test failed"' ERR |
|
5 |
+ |
|
6 |
+# https://github.com/ansible/ansible/issues/61964 |
|
7 |
+ |
|
8 |
+# These tests should return all hosts |
|
9 |
+ansible -i hosts.yml all --limit ,, --list-hosts | tee out ; grep -q 'hosts (3)' out |
|
10 |
+ansible -i hosts.yml ,, --list-hosts | tee out ; grep -q 'hosts (3)' out |
|
11 |
+ansible -i hosts.yml , --list-hosts | tee out ; grep -q 'hosts (3)' out |
|
12 |
+ansible -i hosts.yml all --limit , --list-hosts | tee out ; grep -q 'hosts (3)' out |
|
13 |
+ansible -i hosts.yml all --limit '' --list-hosts | tee out ; grep -q 'hosts (3)' out |
|
14 |
+ |
|
15 |
+ |
|
16 |
+# Only one host |
|
17 |
+ansible -i hosts.yml all --limit ,,host1 --list-hosts | tee out ; grep -q 'hosts (1)' out |
|
18 |
+ansible -i hosts.yml ,,host1 --list-hosts | tee out ; grep -q 'hosts (1)' out |
|
19 |
+ |
|
20 |
+ansible -i hosts.yml all --limit host1,, --list-hosts | tee out ; grep -q 'hosts (1)' out |
|
21 |
+ansible -i hosts.yml host1,, --list-hosts | tee out ; grep -q 'hosts (1)' out |
|
22 |
+ |
|
23 |
+ |
|
24 |
+# Only two hosts |
|
25 |
+ansible -i hosts.yml all --limit host1,,host3 --list-hosts | tee out ; grep -q 'hosts (2)' out |
|
26 |
+ansible -i hosts.yml host1,,host3 --list-hosts | tee out ; grep -q 'hosts (2)' out |
|
27 |
+ |
|
28 |
+ansible -i hosts.yml all --limit 'host1, , ,host3' --list-hosts | tee out ; grep -q 'hosts (2)' out |
|
29 |
+ansible -i hosts.yml 'host1, , ,host3' --list-hosts | tee out ; grep -q 'hosts (2)' out |
|
30 |
+ |
... | ... |
@@ -49,6 +49,10 @@ class TestInventory(unittest.TestCase): |
49 | 49 |
'a:b': ['a', 'b'], |
50 | 50 |
' a : b ': ['a', 'b'], |
51 | 51 |
'foo:bar:baz[1:2]': ['foo', 'bar', 'baz[1:2]'], |
52 |
+ 'a,,b': ['a', 'b'], |
|
53 |
+ 'a, ,b,,c, ,': ['a', 'b', 'c'], |
|
54 |
+ ',': [], |
|
55 |
+ '': [], |
|
52 | 56 |
} |
53 | 57 |
|
54 | 58 |
pattern_lists = [ |