Split up filter integration tests. (#66962)

* Split out json_query filter tests.
* Split out urlsplit filter tests.
* Split out ipaddr filter tests.
* Split out urls filter tests.
* Split out mathstuff filter tests.
* Clean up core filter tests.
pull/66969/head
Matt Clay 5 years ago committed by GitHub
parent 5112feeace
commit 4452f506a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
#!/usr/bin/env bash
set -eux
ANSIBLE_ROLES_PATH=../ ansible-playbook runme.yml "$@"

@ -0,0 +1,3 @@
- hosts: localhost
roles:
- { role: filter_core }

@ -61,42 +61,6 @@
that:
- 'diff_result.stdout == ""'
- name: Verify human_readable
tags: "human_readable"
assert:
that:
- '"1.00 Bytes" == 1|human_readable'
- '"1.00 bits" == 1|human_readable(isbits=True)'
- '"10.00 KB" == 10240|human_readable'
- '"97.66 MB" == 102400000|human_readable'
- '"0.10 GB" == 102400000|human_readable(unit="G")'
- '"0.10 Gb" == 102400000|human_readable(isbits=True, unit="G")'
- name: Verify human_to_bytes
tags: "human_to_bytes"
assert:
that:
- "{{'0'|human_to_bytes}} == 0"
- "{{'0.1'|human_to_bytes}} == 0"
- "{{'0.9'|human_to_bytes}} == 1"
- "{{'1'|human_to_bytes}} == 1"
- "{{'10.00 KB'|human_to_bytes}} == 10240"
- "{{ '11 MB'|human_to_bytes}} == 11534336"
- "{{ '1.1 GB'|human_to_bytes}} == 1181116006"
- "{{'10.00 Kb'|human_to_bytes(isbits=True)}} == 10240"
- name: Verify human_to_bytes (bad string)
set_fact:
bad_string: "{{ '10.00 foo' | human_to_bytes }}"
ignore_errors: yes
tags: human_to_bytes
register: _human_bytes_test
- name: Verify human_to_bytes (bad string)
tags: human_to_bytes
assert:
that: "{{_human_bytes_test.failed}}"
- name: Test extract
assert:
that:
@ -139,62 +103,12 @@
- "'localhost' | extract(hostvars, ['badsubkey', 'subsubkey']) | default('a') == 'a'"
- "('localhost' | extract(hostvars, 'badsubkey')).subsubkey | default('a') == 'a'"
- name: Test json_query filter
assert:
that:
- "users | json_query('[*].hosts[].host') == ['host_a', 'host_b', 'host_c', 'host_d']"
- name: Test hash filter
assert:
that:
- '"{{ "hash" | hash("sha1") }}" == "2346ad27d7568ba9896f1b7da6b5991251debdf2"'
- '"{{ "café" | hash("sha1") }}" == "f424452a9673918c6f09b0cdd35b20be8e6ae7d7"'
- debug:
var: "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit"
verbosity: 1
tags: debug
- name: Test urlsplit filter
assert:
that:
- "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('fragment') == 'fragment'"
- "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('hostname') == 'www.acme.com'"
- "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('netloc') == 'mary:MySecret@www.acme.com:9000'"
- "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('path') == '/dir/index.html'"
- "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('port') == 9000"
- "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('query') == 'query=term'"
- "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('scheme') == 'http'"
- "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('username') == 'mary'"
- "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('password') == 'MySecret'"
- "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit == { 'fragment': 'fragment', 'hostname': 'www.acme.com', 'netloc': 'mary:MySecret@www.acme.com:9000', 'password': 'MySecret', 'path': '/dir/index.html', 'port': 9000, 'query': 'query=term', 'scheme': 'http', 'username': 'mary' }"
- name: Test urlsplit filter bad argument
debug:
var: "'http://www.acme.com:9000/dir/index.html' | urlsplit('bad_filter')"
register: _bad_urlsplit_filter
ignore_errors: yes
- name: Verify urlsplit filter showed an error message
assert:
that:
- _bad_urlsplit_filter is failed
- "'unknown URL component' in _bad_urlsplit_filter.msg"
- name: Test urldecode filter
set_fact:
urldecoded_string: key="@{}é&%£ foo bar '(;\<>""°)
- name: Test urlencode filter
set_fact:
urlencoded_string: '{{ urldecoded_string|urlencode }}'
- name: Verify urlencode en urldecode
assert:
that:
- urldecoded_string == urlencoded_string|urldecode
- name: Flatten tests
block:
- name: use flatten
@ -274,46 +188,6 @@
- "'00:00:00' | random_mac(seed='test') == '00:00:00' | random_mac(seed='test')"
- "'00:00:00' | random_mac(seed='test') != '00:00:00' | random_mac(seed='another_test')"
- name: Verify that union can be chained
vars:
unions: '{{ [1,2,3]|union([4,5])|union([6,7]) }}'
assert:
that:
- "unions|type_debug == 'list'"
- "unions|length == 7"
- name: Test union with unhashable item
vars:
unions: '{{ [1,2,3]|union([{}]) }}'
assert:
that:
- "unions|type_debug == 'list'"
- "unions|length == 4"
- name: Test ipaddr filter
assert:
that:
- "'192.168.0.1/32' | ipaddr('netmask') == '255.255.255.255'"
- "'192.168.0.1/24' | ipaddr('netmask') == '255.255.255.0'"
- "not '192.168.0.1/31' | ipaddr('broadcast')"
- "'192.168.0.1/24' | ipaddr('broadcast') == '192.168.0.255'"
- "'192.168.0.1/24' | ipaddr('prefix') == 24"
- "'192.168.0.1/24' | ipaddr('address') == '192.168.0.1'"
- "'192.168.0.1/24' | ipaddr('network') == '192.168.0.0'"
- "'fe80::dead:beef/64' | ipaddr('broadcast') == 'fe80::ffff:ffff:ffff:ffff'"
- "'::1/120' | ipaddr('netmask') == 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00'"
- "{{ subnets | ipaddr(1) }} == ['10.1.1.1/24', '10.1.2.1/24']"
- "{{ subnets | ipaddr('1') }} == ['10.1.1.1/24', '10.1.2.1/24']"
- "{{ subnets | ipaddr(-1) }} == ['10.1.1.255/24', '10.1.2.255/24']"
- "{{ subnets | ipaddr('-1') }} == ['10.1.1.255/24', '10.1.2.255/24']"
- "'{{ prefix | ipaddr(1) }}' == '10.1.1.1/24'"
- "'{{ prefix | ipaddr('1') }}' == '10.1.1.1/24'"
- "'{{ prefix | ipaddr('network') }}' == '10.1.1.0'"
- "'{{ prefix | ipaddr('-1') }}' == '10.1.1.255/24'"
vars:
subnets: ['10.1.1.0/24', '10.1.2.0/24']
prefix: '10.1.1.0/24'
- name: Ensure dict2items works with hostvars
debug:
msg: "{{ item.key }}"

@ -5,18 +5,6 @@ some_structure:
warp: 9
where: endor
users:
- name: steve
hosts:
- host: host_a
password: abc
- host: host_b
- name: bill
hosts:
- host: host_c
password: default
- host: host_d
other_data:
level1:
foo: bar

@ -0,0 +1,3 @@
shippable/posix/group2
skip/python2.6 # filters are controller only, and we no longer support Python 2.6 on the controller
skip/aix

@ -7,6 +7,6 @@ source virtualenv.sh
# Requirements have to be installed prior to running ansible-playbook
# because plugins and requirements are loaded before the task runs
pip install jmespath netaddr
pip install netaddr
ANSIBLE_ROLES_PATH=../ ansible-playbook filters.yml "$@"
ANSIBLE_ROLES_PATH=../ ansible-playbook runme.yml "$@"

@ -0,0 +1,3 @@
- hosts: localhost
roles:
- { role: filter_ipaddr }

@ -0,0 +1,23 @@
- name: Test ipaddr filter
assert:
that:
- "'192.168.0.1/32' | ipaddr('netmask') == '255.255.255.255'"
- "'192.168.0.1/24' | ipaddr('netmask') == '255.255.255.0'"
- "not '192.168.0.1/31' | ipaddr('broadcast')"
- "'192.168.0.1/24' | ipaddr('broadcast') == '192.168.0.255'"
- "'192.168.0.1/24' | ipaddr('prefix') == 24"
- "'192.168.0.1/24' | ipaddr('address') == '192.168.0.1'"
- "'192.168.0.1/24' | ipaddr('network') == '192.168.0.0'"
- "'fe80::dead:beef/64' | ipaddr('broadcast') == 'fe80::ffff:ffff:ffff:ffff'"
- "'::1/120' | ipaddr('netmask') == 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00'"
- "{{ subnets | ipaddr(1) }} == ['10.1.1.1/24', '10.1.2.1/24']"
- "{{ subnets | ipaddr('1') }} == ['10.1.1.1/24', '10.1.2.1/24']"
- "{{ subnets | ipaddr(-1) }} == ['10.1.1.255/24', '10.1.2.255/24']"
- "{{ subnets | ipaddr('-1') }} == ['10.1.1.255/24', '10.1.2.255/24']"
- "'{{ prefix | ipaddr(1) }}' == '10.1.1.1/24'"
- "'{{ prefix | ipaddr('1') }}' == '10.1.1.1/24'"
- "'{{ prefix | ipaddr('network') }}' == '10.1.1.0'"
- "'{{ prefix | ipaddr('-1') }}' == '10.1.1.255/24'"
vars:
subnets: ['10.1.1.0/24', '10.1.2.0/24']
prefix: '10.1.1.0/24'

@ -0,0 +1,3 @@
shippable/posix/group2
skip/python2.6 # filters are controller only, and we no longer support Python 2.6 on the controller
skip/aix

@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -eux
source virtualenv.sh
# Requirements have to be installed prior to running ansible-playbook
# because plugins and requirements are loaded before the task runs
pip install jmespath
ANSIBLE_ROLES_PATH=../ ansible-playbook runme.yml "$@"

@ -0,0 +1,3 @@
- hosts: localhost
roles:
- { role: filter_json_query }

@ -0,0 +1,4 @@
- name: Test json_query filter
assert:
that:
- "users | json_query('[*].hosts[].host') == ['host_a', 'host_b', 'host_c', 'host_d']"

@ -0,0 +1,11 @@
users:
- name: steve
hosts:
- host: host_a
password: abc
- host: host_b
- name: bill
hosts:
- host: host_c
password: default
- host: host_d

@ -0,0 +1,3 @@
shippable/posix/group2
skip/python2.6 # filters are controller only, and we no longer support Python 2.6 on the controller
skip/aix

@ -0,0 +1,51 @@
- name: Verify human_readable
tags: "human_readable"
assert:
that:
- '"1.00 Bytes" == 1|human_readable'
- '"1.00 bits" == 1|human_readable(isbits=True)'
- '"10.00 KB" == 10240|human_readable'
- '"97.66 MB" == 102400000|human_readable'
- '"0.10 GB" == 102400000|human_readable(unit="G")'
- '"0.10 Gb" == 102400000|human_readable(isbits=True, unit="G")'
- name: Verify human_to_bytes
tags: "human_to_bytes"
assert:
that:
- "{{'0'|human_to_bytes}} == 0"
- "{{'0.1'|human_to_bytes}} == 0"
- "{{'0.9'|human_to_bytes}} == 1"
- "{{'1'|human_to_bytes}} == 1"
- "{{'10.00 KB'|human_to_bytes}} == 10240"
- "{{ '11 MB'|human_to_bytes}} == 11534336"
- "{{ '1.1 GB'|human_to_bytes}} == 1181116006"
- "{{'10.00 Kb'|human_to_bytes(isbits=True)}} == 10240"
- name: Verify human_to_bytes (bad string)
set_fact:
bad_string: "{{ '10.00 foo' | human_to_bytes }}"
ignore_errors: yes
tags: human_to_bytes
register: _human_bytes_test
- name: Verify human_to_bytes (bad string)
tags: human_to_bytes
assert:
that: "{{_human_bytes_test.failed}}"
- name: Verify that union can be chained
vars:
unions: '{{ [1,2,3]|union([4,5])|union([6,7]) }}'
assert:
that:
- "unions|type_debug == 'list'"
- "unions|length == 7"
- name: Test union with unhashable item
vars:
unions: '{{ [1,2,3]|union([{}]) }}'
assert:
that:
- "unions|type_debug == 'list'"
- "unions|length == 4"

@ -0,0 +1,3 @@
shippable/posix/group2
skip/python2.6 # filters are controller only, and we no longer support Python 2.6 on the controller
skip/aix

@ -0,0 +1,12 @@
- name: Test urldecode filter
set_fact:
urldecoded_string: key="@{}é&%£ foo bar '(;\<>""°)
- name: Test urlencode filter
set_fact:
urlencoded_string: '{{ urldecoded_string|urlencode }}'
- name: Verify urlencode en urldecode
assert:
that:
- urldecoded_string == urlencoded_string|urldecode

@ -0,0 +1,3 @@
shippable/posix/group2
skip/python2.6 # filters are controller only, and we no longer support Python 2.6 on the controller
skip/aix

@ -0,0 +1,30 @@
- debug:
var: "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit"
verbosity: 1
tags: debug
- name: Test urlsplit filter
assert:
that:
- "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('fragment') == 'fragment'"
- "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('hostname') == 'www.acme.com'"
- "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('netloc') == 'mary:MySecret@www.acme.com:9000'"
- "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('path') == '/dir/index.html'"
- "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('port') == 9000"
- "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('query') == 'query=term'"
- "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('scheme') == 'http'"
- "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('username') == 'mary'"
- "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit('password') == 'MySecret'"
- "'http://mary:MySecret@www.acme.com:9000/dir/index.html?query=term#fragment' | urlsplit == { 'fragment': 'fragment', 'hostname': 'www.acme.com', 'netloc': 'mary:MySecret@www.acme.com:9000', 'password': 'MySecret', 'path': '/dir/index.html', 'port': 9000, 'query': 'query=term', 'scheme': 'http', 'username': 'mary' }"
- name: Test urlsplit filter bad argument
debug:
var: "'http://www.acme.com:9000/dir/index.html' | urlsplit('bad_filter')"
register: _bad_urlsplit_filter
ignore_errors: yes
- name: Verify urlsplit filter showed an error message
assert:
that:
- _bad_urlsplit_filter is failed
- "'unknown URL component' in _bad_urlsplit_filter.msg"

@ -1,4 +0,0 @@
- hosts: localhost
gather_facts: yes
roles:
- { role: filters }

@ -1,2 +0,0 @@
dependencies:
- prepare_tests
Loading…
Cancel
Save