From 1f8173b797354d16be8c85c5fe347611e2426190 Mon Sep 17 00:00:00 2001 From: Vladimir Botka Date: Sat, 12 Dec 2020 17:21:29 +0100 Subject: [PATCH] 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 --- .../filter_list/tasks/lists_mergeby.yml | 64 +++++++++++++++++++ .../targets/filter_list/tasks/main.yml | 6 +- .../targets/filter_list/vars/main.yml | 5 ++ 3 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 tests/integration/targets/filter_list/tasks/lists_mergeby.yml diff --git a/tests/integration/targets/filter_list/tasks/lists_mergeby.yml b/tests/integration/targets/filter_list/tasks/lists_mergeby.yml new file mode 100644 index 0000000000..903ae78c3c --- /dev/null +++ b/tests/integration/targets/filter_list/tasks/lists_mergeby.yml @@ -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' diff --git a/tests/integration/targets/filter_list/tasks/main.yml b/tests/integration/targets/filter_list/tasks/main.yml index 4abf98c897..1e5773c638 100644 --- a/tests/integration/targets/filter_list/tasks/main.yml +++ b/tests/integration/targets/filter_list/tasks/main.yml @@ -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 diff --git a/tests/integration/targets/filter_list/vars/main.yml b/tests/integration/targets/filter_list/vars/main.yml index 1867653441..13887e176c 100644 --- a/tests/integration/targets/filter_list/vars/main.yml +++ b/tests/integration/targets/filter_list/vars/main.yml @@ -20,3 +20,8 @@ list3: param02: myparam04 - name: myname03 param03: myparam03 + +list4: + - name: myname01 + param01: myparam01 + - myname02