remove_keys: Add complex integration tests. (#204)

* remove_keys: Add complex integration tests.

* Changelog

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix lint

* fix more lint

* rewrite test

* fix lint

* fix lint again

* fix lint final

* fix lint warnings

* remove unnecessary file

* fix spacing

* added seprate file for vars

* fix intergration tests

---------

Co-authored-by: Vinay M <63404819+roverflow@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: roverflow <roverflow5@gmail.com>
pull/362/head^2
Vladimir Botka 2024-07-22 08:52:48 +02:00 committed by GitHub
parent 41339232c3
commit 6c1c3a4b81
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 165 additions and 0 deletions

View File

@ -0,0 +1,3 @@
---
trivial:
- Add integration tests for remove_keys

View File

@ -0,0 +1,143 @@
---
- name: Include expected output data
ansible.builtin.include_vars:
file: complex.yaml
- name: Test for remove_keys
vars:
target:
- { p3: a }
- { p3: b }
- { p3: c }
tags: remove_keys
block:
- name: Test remove_keys debug
ansible.builtin.debug:
msg: "{{ l1 | ansible.utils.remove_keys(target=['p1', 'p2']) }}"
register: result_l1
- name: Test remove_keys assert
ansible.builtin.assert:
that:
- result_l1["msg"] == target
- name: Test map remove_keys
vars:
target:
- - { p3: a }
- { p3: b }
- { p3: c }
- - { p3: a }
- { p3: b }
- { p3: c }
- - { p3: a }
- { p3: b }
- { p3: c }
tags: remove_keys
block:
- name: Test remove_keys map debug
ansible.builtin.debug:
msg: "{{ l2 | map('ansible.utils.remove_keys', target=['p1', 'p2']) | list }}"
register: result_l2
- name: Convert to yaml
ansible.builtin.debug:
var: result_l2|to_yaml
when: debug_test|d(false)|bool
- name: Test remove_keys map assert
ansible.builtin.assert:
that:
- result_l2["msg"] == target
- name: Test remove_keys starts_with
vars:
target:
- { p3: a }
- { p3: b }
- { p3: c }
tags: remove_keys_starts_with_2
block:
- name: Test remove_keys starts_with debug msg
ansible.builtin.debug:
msg: "{{ l1 | ansible.utils.remove_keys(target=['p1', 'p2'], matching_parameter='starts_with') }}"
register: result_3
- name: Test remove_keys starts_with convert to yaml
ansible.builtin.debug:
var: result_3|to_yaml
when: debug_test|d(false)|bool
- name: Test remove_keys assert
ansible.builtin.assert:
that: result_3["msg"] == target
- name: Test remove_keys starts_with 'p'
tags: remove_keys_starts_with_1
block:
- name: Test remove_keys starts_with 'p' debug
ansible.builtin.debug:
msg: "{{ l1 | ansible.utils.remove_keys(target=['p'], matching_parameter='starts_with') }}"
register: result_4
- name: Test remove_keys starts_with 'p' convert to yaml
ansible.builtin.debug:
var: result_4|to_yaml
when: debug_test|d(false)|bool
- name: Test remove_keys assert
ansible.builtin.assert:
that: result_4["msg"] == []
- name: Test remove_keys ends_with
vars:
target:
- { p3: a }
- { p3: b }
- { p3: c }
tags: remove_keys_ends_with_2
block:
- name: Test remove_keys ends_with
ansible.builtin.debug:
msg: "{{ l1 | ansible.utils.remove_keys(target=['p1', 'p2'], matching_parameter='ends_with') }}"
register: result_5
- name: Test remove_keys ends_with conver to yaml
ansible.builtin.debug:
var: result_5|to_yaml
when: debug_test|d(false)|bool
- name: Test remove_keys ends_with assert
ansible.builtin.assert:
that: result_5["msg"] == target
- name: Test remove_keys ends_with '2'
vars:
target:
- { p1: a, p3: a }
- { p1: b, p3: b }
- { p1: c, p3: c }
tags: remove_keys_ends_with_1
block:
- name: Test remove_keys ends_with '2' debug
ansible.builtin.debug:
msg: "{{ l1 | ansible.utils.remove_keys(target=['2'], matching_parameter='ends_with') }}"
register: result_6
- name: Test remove_keys ends_with '2' debug convert to yaml
ansible.builtin.debug:
var: result_6|to_yaml
when: debug_test|d(false)|bool
- name: Test remove_keys ends_with '2' assert
ansible.builtin.assert:
that: result_6["msg"] == target
- name: Test remove_keys regex
vars:
target:
- { p3: a }
- { p3: b }
- { p3: c }
tags: remove_keys_regex
block:
- name: Test remove_keys regex debug
ansible.builtin.debug:
msg: "{{ l1 | ansible.utils.remove_keys(target=['p1', 'p2'], matching_parameter='regex') }}"
register: result_7
- name: Test remove_keys regex debug conver to yaml
ansible.builtin.debug:
var: result_7|to_yaml
when: debug_test|d(false)|bool
- name: Test remove_keys regex assert
ansible.builtin.assert:
that: result_7["msg"] == target

View File

@ -0,0 +1,19 @@
---
l1:
- { p1: a, p2: a, p3: a }
- { p1: b, p2: b, p3: b }
- { p1: c, p2: c, p3: c }
l2:
- - { p1: a, p2: a, p3: a }
- { p1: b, p2: b, p3: b }
- { p1: c, p2: c, p3: c }
- - { p1: a, p2: a, p3: a }
- { p1: b, p2: b, p3: b }
- { p1: c, p2: c, p3: c }
- - { p1: a, p2: a, p3: a }
- { p1: b, p2: b, p3: b }
- { p1: c, p2: c, p3: c }
l3:
- { p1_key_o1: a, p2_key_o2: a, p3_key_o3: a }
- { p1_key_o4: b, p2_key_o5: b, p3_key_o6: b }
- { p1_key_o7: c, p2_key_o8: c, p3_key_o9: c }