mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-08 14:20:04 -07:00
Add groupby_as_dict filter (#2323)
* Add groupby_as_dict filter. * Test all error cases.
This commit is contained in:
parent
23dda56913
commit
384655e15c
5 changed files with 123 additions and 0 deletions
2
tests/integration/targets/filter_groupby/aliases
Normal file
2
tests/integration/targets/filter_groupby/aliases
Normal file
|
@ -0,0 +1,2 @@
|
|||
shippable/posix/group4
|
||||
skip/python2.6 # filters are controller only, and we no longer support Python 2.6 on the controller
|
45
tests/integration/targets/filter_groupby/tasks/main.yml
Normal file
45
tests/integration/targets/filter_groupby/tasks/main.yml
Normal file
|
@ -0,0 +1,45 @@
|
|||
---
|
||||
- name: Test functionality
|
||||
assert:
|
||||
that:
|
||||
- list1 | community.general.groupby_as_dict('name') == dict1
|
||||
|
||||
- name: 'Test error: not a list'
|
||||
set_fact:
|
||||
test: "{{ list_no_list | community.general.groupby_as_dict('name') }}"
|
||||
ignore_errors: true
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.msg == 'Input is not a sequence'
|
||||
|
||||
- name: 'Test error: list element not a mapping'
|
||||
set_fact:
|
||||
test: "{{ list_no_dict | community.general.groupby_as_dict('name') }}"
|
||||
ignore_errors: true
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.msg == 'Sequence element #0 is not a mapping'"
|
||||
|
||||
- name: 'Test error: list element does not have attribute'
|
||||
set_fact:
|
||||
test: "{{ list_no_attribute | community.general.groupby_as_dict('name') }}"
|
||||
ignore_errors: true
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.msg == 'Attribute not contained in element #1 of sequence'"
|
||||
|
||||
- name: 'Test error: attribute collision'
|
||||
set_fact:
|
||||
test: "{{ list_collision | community.general.groupby_as_dict('name') }}"
|
||||
ignore_errors: true
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- result.msg == "Multiple sequence entries have attribute value 'a'"
|
31
tests/integration/targets/filter_groupby/vars/main.yml
Normal file
31
tests/integration/targets/filter_groupby/vars/main.yml
Normal file
|
@ -0,0 +1,31 @@
|
|||
---
|
||||
list1:
|
||||
- name: a
|
||||
x: y
|
||||
- name: b
|
||||
z: 1
|
||||
|
||||
dict1:
|
||||
a:
|
||||
name: a
|
||||
x: y
|
||||
b:
|
||||
name: b
|
||||
z: 1
|
||||
|
||||
list_no_list:
|
||||
a:
|
||||
name: a
|
||||
|
||||
list_no_dict:
|
||||
- []
|
||||
- 1
|
||||
|
||||
list_no_attribute:
|
||||
- name: a
|
||||
foo: baz
|
||||
- foo: bar
|
||||
|
||||
list_collision:
|
||||
- name: a
|
||||
- name: a
|
Loading…
Add table
Add a link
Reference in a new issue