keep_keys: Add complex integration tests. (#203)
* keep_keys: Add complex integration tests. * Changelog * fix lint * fix lint warnings * fix final warning * add seprate file for vars --------- Co-authored-by: Vinay M <63404819+roverflow@users.noreply.github.com> Co-authored-by: roverflow <roverflow5@gmail.com>pull/204/head^2
parent
6425ea2299
commit
41339232c3
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
trivial:
|
||||
- Add integration tests for keep_keys
|
|
@ -0,0 +1,129 @@
|
|||
---
|
||||
- name: Include expected output data
|
||||
ansible.builtin.include_vars:
|
||||
file: complex.yaml
|
||||
|
||||
- name: Test keep_keys
|
||||
vars:
|
||||
result: "{{ l1 | ansible.utils.keep_keys(target=['p1', 'p2']) }}"
|
||||
target:
|
||||
- { p1: a, p2: a }
|
||||
- { p1: b, p2: b }
|
||||
- { p1: c, p2: c }
|
||||
tags: keep_keys
|
||||
block:
|
||||
- name: Test keep_keys debug
|
||||
ansible.builtin.debug:
|
||||
var: result|to_yaml
|
||||
when: debug_test|d(false)|bool
|
||||
- name: Test keep_keys assert
|
||||
ansible.builtin.assert:
|
||||
that: result == target
|
||||
|
||||
- name: Test map keep_keys
|
||||
vars:
|
||||
result: "{{ l2 | map('ansible.utils.keep_keys', target=['p1', 'p2']) | list }}"
|
||||
target:
|
||||
- - { p1: a, p2: a }
|
||||
- { p1: b, p2: b }
|
||||
- { p1: c, p2: c }
|
||||
- - { p1: a, p2: a }
|
||||
- { p1: b, p2: b }
|
||||
- { p1: c, p2: c }
|
||||
- - { p1: a, p2: a }
|
||||
- { p1: b, p2: b }
|
||||
- { p1: c, p2: c }
|
||||
tags: map_keep_keys
|
||||
block:
|
||||
- name: Test map keep_keys debug
|
||||
ansible.builtin.debug:
|
||||
var: result|to_yaml
|
||||
when: debug_test|d(false)|bool
|
||||
- name: Test map keep_keys assert
|
||||
ansible.builtin.assert:
|
||||
that: result == target
|
||||
|
||||
- name: Test keep_keys starts_with
|
||||
vars:
|
||||
result: "{{ l1 | ansible.utils.keep_keys(target=['p1', 'p2'], matching_parameter='starts_with') }}"
|
||||
target:
|
||||
- { p1: a, p2: a }
|
||||
- { p1: b, p2: b }
|
||||
- { p1: c, p2: c }
|
||||
tags: keep_keys_starts_with_2
|
||||
block:
|
||||
- name: Test keep_keys starts_with debug
|
||||
ansible.builtin.debug:
|
||||
var: result|to_yaml
|
||||
when: debug_test|d(false)|bool
|
||||
- name: Test keep_keys starts_with assert
|
||||
ansible.builtin.assert:
|
||||
that: result == target
|
||||
|
||||
- name: Test keep_keys starts_with 'p'
|
||||
vars:
|
||||
result: "{{ l1 | ansible.utils.keep_keys(target=['p'], matching_parameter='starts_with') }}"
|
||||
target:
|
||||
- { p1: a, p2: a, p3: a }
|
||||
- { p1: b, p2: b, p3: b }
|
||||
- { p1: c, p2: c, p3: c }
|
||||
tags: keep_keys_starts_with_1
|
||||
block:
|
||||
- name: Test keep_keys starts_with 'p' debug
|
||||
ansible.builtin.debug:
|
||||
var: result|to_yaml
|
||||
when: debug_test|d(false)|bool
|
||||
- name: Test keep_keys starts_with 'p' assert
|
||||
ansible.builtin.assert:
|
||||
that: result == target
|
||||
|
||||
- name: Test keep_keys ends_with
|
||||
vars:
|
||||
result: "{{ l1 | ansible.utils.keep_keys(target=['p1', 'p2'], matching_parameter='ends_with') }}"
|
||||
target:
|
||||
- { p1: a, p2: a }
|
||||
- { p1: b, p2: b }
|
||||
- { p1: c, p2: c }
|
||||
tags: keep_keys_ends_with_2
|
||||
block:
|
||||
- name: Test keep_keys end_with debug
|
||||
ansible.builtin.debug:
|
||||
var: result|to_yaml
|
||||
when: debug_test|d(false)|bool
|
||||
- name: Test keep_keys end_with assert
|
||||
ansible.builtin.assert:
|
||||
that: result == target
|
||||
|
||||
- name: Test keep_keys ends_with '2'
|
||||
vars:
|
||||
result: "{{ l1 | ansible.utils.keep_keys(target=['2'], matching_parameter='ends_with') }}"
|
||||
target:
|
||||
- { p2: a }
|
||||
- { p2: b }
|
||||
- { p2: c }
|
||||
tags: keep_keys_ends_with_1
|
||||
block:
|
||||
- name: Test keep_keys end_with '2' debug
|
||||
ansible.builtin.debug:
|
||||
var: result|to_yaml
|
||||
when: debug_test|d(false)|bool
|
||||
- name: Test keep_keys end_with '2' assert
|
||||
ansible.builtin.assert:
|
||||
that: result == target
|
||||
|
||||
- name: Test keep_keys regex
|
||||
vars:
|
||||
result: "{{ l1 | ansible.utils.keep_keys(target=['p1', 'p2'], matching_parameter='regex') }}"
|
||||
target:
|
||||
- { p1: a, p2: a }
|
||||
- { p1: b, p2: b }
|
||||
- { p1: c, p2: c }
|
||||
tags: keep_keys_regex
|
||||
block:
|
||||
- name: Test keep_keys regex debug
|
||||
ansible.builtin.debug:
|
||||
var: result|to_yaml
|
||||
when: debug_test|d(false)|bool
|
||||
- name: Test keep_keys regex assert
|
||||
ansible.builtin.assert:
|
||||
that: result == target
|
|
@ -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 }
|
Loading…
Reference in New Issue