mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-09-30 13:33:21 -07:00
New Filter plugin from_csv (#2037)
* Added from_csv filter and integration tests * Cleaning up whitespace * Adding changelog fragment * Updated changelog fragment name * Removed temp fragment * Refactoring csv functions Part 1 * Syncing refactored csv modules/filters * Adding unit tests for csv Module_Util * Updating changelog fragment * Correcting whitespace in unit test * Improving changelog fragment Co-authored-by: Felix Fontein <felix@fontein.de> * Update changelogs/fragments/2037-add-from-csv-filter.yml Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
c147d2fb98
commit
6529390901
8 changed files with 383 additions and 47 deletions
2
tests/integration/targets/filter_from_csv/aliases
Normal file
2
tests/integration/targets/filter_from_csv/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
|
49
tests/integration/targets/filter_from_csv/tasks/main.yml
Normal file
49
tests/integration/targets/filter_from_csv/tasks/main.yml
Normal file
|
@ -0,0 +1,49 @@
|
|||
####################################################################
|
||||
# WARNING: These are designed specifically for Ansible tests #
|
||||
# and should not be used as examples of how to write Ansible roles #
|
||||
####################################################################
|
||||
|
||||
- name: Parse valid csv input
|
||||
assert:
|
||||
that:
|
||||
- "valid_comma_separated | community.general.from_csv == expected_result"
|
||||
|
||||
- name: Parse valid csv input containing spaces with/without skipinitialspace=True
|
||||
assert:
|
||||
that:
|
||||
- "valid_comma_separated_spaces | community.general.from_csv(skipinitialspace=True) == expected_result"
|
||||
- "valid_comma_separated_spaces | community.general.from_csv != expected_result"
|
||||
|
||||
- name: Parse valid csv input with no headers with/without specifiying fieldnames
|
||||
assert:
|
||||
that:
|
||||
- "valid_comma_separated_no_headers | community.general.from_csv(fieldnames=['id','name','role']) == expected_result"
|
||||
- "valid_comma_separated_no_headers | community.general.from_csv != expected_result"
|
||||
|
||||
- name: Parse valid pipe-delimited csv input with/without delimiter=|
|
||||
assert:
|
||||
that:
|
||||
- "valid_pipe_separated | community.general.from_csv(delimiter='|') == expected_result"
|
||||
- "valid_pipe_separated | community.general.from_csv != expected_result"
|
||||
|
||||
- name: Register result of invalid csv input when strict=False
|
||||
debug:
|
||||
var: "invalid_comma_separated | community.general.from_csv"
|
||||
register: _invalid_csv_strict_false
|
||||
|
||||
- name: Test invalid csv input when strict=False is successful
|
||||
assert:
|
||||
that:
|
||||
- _invalid_csv_strict_false is success
|
||||
|
||||
- name: Register result of invalid csv input when strict=True
|
||||
debug:
|
||||
var: "invalid_comma_separated | community.general.from_csv(strict=True)"
|
||||
register: _invalid_csv_strict_true
|
||||
ignore_errors: True
|
||||
|
||||
- name: Test invalid csv input when strict=True is failed
|
||||
assert:
|
||||
that:
|
||||
- _invalid_csv_strict_true is failed
|
||||
- _invalid_csv_strict_true.msg is match('Unable to process file:.*')
|
26
tests/integration/targets/filter_from_csv/vars/main.yml
Normal file
26
tests/integration/targets/filter_from_csv/vars/main.yml
Normal file
|
@ -0,0 +1,26 @@
|
|||
valid_comma_separated: |
|
||||
id,name,role
|
||||
1,foo,bar
|
||||
2,bar,baz
|
||||
valid_comma_separated_spaces: |
|
||||
id,name,role
|
||||
1, foo, bar
|
||||
2, bar, baz
|
||||
valid_comma_separated_no_headers: |
|
||||
1,foo,bar
|
||||
2,bar,baz
|
||||
valid_pipe_separated: |
|
||||
id|name|role
|
||||
1|foo|bar
|
||||
2|bar|baz
|
||||
invalid_comma_separated: |
|
||||
id,name,role
|
||||
1,foo,bar
|
||||
2,"b"ar",baz
|
||||
expected_result:
|
||||
- id: '1'
|
||||
name: foo
|
||||
role: bar
|
||||
- id: '2'
|
||||
name: bar
|
||||
role: baz
|
Loading…
Add table
Add a link
Reference in a new issue