Skip to content

Commit a28e84d

Browse files
committed
add tests for hostlist_expression with padded hostnames
1 parent 0f440ee commit a28e84d

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

tests/filter.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@
55
vars:
66
grouped_0: "{{ groups['mock_group_0'] | hostlist_expression }}"
77
grouped_1: "{{ groups['mock_group_1'] | hostlist_expression }}"
8+
grouped_2: "{{ groups['mock_group_2'] | hostlist_expression }}"
89
tasks:
9-
- name: Show grouped mock-group-0
10-
debug: var=grouped_0
11-
- name: Show grouped mock-group-1
12-
debug: var=grouped_1
1310
- name: Test filter
1411
assert:
15-
that:
16-
- "['localhost-0-[0-3,5]', 'localhost-non-numerical'] == grouped_0"
17-
- "['localhost-1-[1-2,4-5,10]', 'localhost-2-[1-3]'] == grouped_1"
18-
12+
that: item.result == item.expected
13+
fail_msg: |
14+
expected: {{ item.expected }}
15+
got: {{ item.result }}
16+
loop:
17+
- result: "{{ grouped_0 }}"
18+
expected: ['localhost-0-[0-3,5]', 'localhost-non-numerical']
19+
- result: "{{ grouped_1 }}"
20+
expected: ['localhost-1-[1-2,4-5,10]', 'localhost-2-[1-3]']
21+
- result: "{{ grouped_2 }}"
22+
expected: ['localhost-[1,0001-0003,0008,0010]', 'localhost-admin']
1923
...

tests/inventory-mock-groups

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,15 @@ localhost-1-10 ansible_host=127.0.0.1 ansible_connection='local' ansible_pyt
1515
localhost-2-1 ansible_host=127.0.0.1 ansible_connection='local' ansible_python_interpreter='/usr/bin/env python'
1616
localhost-2-2 ansible_host=127.0.0.1 ansible_connection='local' ansible_python_interpreter='/usr/bin/env python'
1717
localhost-2-3 ansible_host=127.0.0.1 ansible_connection='local' ansible_python_interpreter='/usr/bin/env python'
18+
19+
[mock_group_2]
20+
# test padding:
21+
# $ scontrol show hostlist localhost-admin,localhost-0001,localhost-0002,localhost-0003,localhost-0008,localhost-0010,localhost-1
22+
# localhost-admin,localhost-[0001-0003,0008,0010,1]
23+
localhost-0001
24+
localhost-1
25+
localhost-0010
26+
localhost-admin
27+
localhost-0002
28+
localhost-0008
29+
localhost-0003

0 commit comments

Comments
 (0)