mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 21:00:22 -07:00
Add counter filter (#3921)
* Add counter filter * move counter filter doc to existing chapter * Use existing typerror exception from Counter * Match counter filter example task name and output
This commit is contained in:
parent
a2f72be6c8
commit
9642a15d34
6 changed files with 159 additions and 0 deletions
2
tests/integration/targets/filter_counter/aliases
Normal file
2
tests/integration/targets/filter_counter/aliases
Normal file
|
@ -0,0 +1,2 @@
|
|||
shippable/posix/group2
|
||||
skip/python2.6 # filters are controller only, and we no longer support Python 2.6 on the controller
|
37
tests/integration/targets/filter_counter/tasks/main.yml
Normal file
37
tests/integration/targets/filter_counter/tasks/main.yml
Normal file
|
@ -0,0 +1,37 @@
|
|||
---
|
||||
####################################################################
|
||||
# WARNING: These are designed specifically for Ansible tests #
|
||||
# and should not be used as examples of how to write Ansible roles #
|
||||
####################################################################
|
||||
|
||||
- name: test counter filter
|
||||
assert:
|
||||
that:
|
||||
- "('abca' | community.general.counter) == {'a': 2, 'b': 1, 'c': 1}"
|
||||
- "(['apple', 'pear', 'pear'] | community.general.counter) == {'apple': 1, 'pear': 2}"
|
||||
- "([1, 2, 2, 3] | community.general.counter) == {1: 1, 2: 2, 3: 1}"
|
||||
- "([1.11, 1.11, 1.12] | community.general.counter) == {1.11: 2, 1.12: 1}"
|
||||
|
||||
- name: test fail argument not a sequence
|
||||
debug:
|
||||
msg: "{{ {'a': 'b'} | community.general.counter }}"
|
||||
ignore_errors: yes
|
||||
register: res
|
||||
|
||||
- name: verify test fail argument not a sequence
|
||||
assert:
|
||||
that:
|
||||
- res is failed
|
||||
- res.msg is match('Argument for community.general.counter must be a sequence')
|
||||
|
||||
- name: test fail element not hashable
|
||||
debug:
|
||||
msg: "{{ [{'a': 'b'}] | community.general.counter }}"
|
||||
ignore_errors: yes
|
||||
register: res
|
||||
|
||||
- name: verify test fail element not hashable
|
||||
assert:
|
||||
that:
|
||||
- res is failed
|
||||
- res.msg is match('community.general.counter needs a sequence with hashable elements')
|
Loading…
Add table
Add a link
Reference in a new issue