1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Added integration tests for target filter_list (#1477)

* Added integration tests for target filter_list

* Added false negative tests to lists_mergeby

* Fixed tests lists_mergeby
This commit is contained in:
Vladimir Botka 2020-12-12 17:21:29 +01:00 committed by GitHub
parent 8e53b3df6f
commit 1f8173b797
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 70 additions and 5 deletions

View file

@ -0,0 +1,64 @@
---
- name: Test lists merged by attribute name
assert:
that:
- "(list1 | community.general.lists_mergeby(list2, 'name') | list |
difference(list3) | length) == 0"
- name: Test list1 empty
assert:
that:
- "([] | community.general.lists_mergeby(list2, 'name') | list |
difference(list2) | length) == 0"
- name: Test list2 empty
assert:
that:
- "(list1 | community.general.lists_mergeby([], 'name') | list |
difference(list1) | length) == 0"
- name: Test all lists empty
assert:
that:
- "([] | community.general.lists_mergeby([], 'name') | list |
difference(list1) | length) == 0"
- name: First argument must be list
set_fact:
my_list: "{{ {'x': 'y'} | community.general.lists_mergeby(list2, 'name') }}"
register: result
ignore_errors: true
- assert:
that:
- result is failed
- '"First argument for community.general.lists_mergeby must be list." in result.msg'
- name: Second argument must be list
set_fact:
my_list: "{{ list1 | community.general.lists_mergeby({'x': 'y'}, 'name') }}"
register: result
ignore_errors: true
- assert:
that:
- result is failed
- '"Second argument for community.general.lists_mergeby must be list." in result.msg'
- name: Third argument must be string
set_fact:
my_list: "{{ list1 | community.general.lists_mergeby(list2, {'x': 'y'}) }}"
register: result
ignore_errors: true
- assert:
that:
- result is failed
- '"Third argument for community.general.lists_mergeby must be string." in result.msg'
- name: Elements of list must be dictionaries
set_fact:
my_list: "{{ list4 | community.general.lists_mergeby(list2, 'name') }}"
register: result
ignore_errors: true
- assert:
that:
- result is failed
- '"Elements of list arguments for lists_mergeby must be dictionaries." in result.msg'

View file

@ -1,6 +1,2 @@
---
- name: Test lists merged by attribute name
assert:
that:
- "(list1 | community.general.lists_mergeby(list2, 'name') | list |
difference(list3) | length) == 0"
- include_tasks: lists_mergeby.yml

View file

@ -20,3 +20,8 @@ list3:
param02: myparam04
- name: myname03
param03: myparam03
list4:
- name: myname01
param01: myparam01
- myname02