mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-08 15:14:20 -07:00
New filter plugins: hashids_encode and hashids_decode (#2244)
* New filters hashids_encode and hashids_decode * Adding changelog * Correcting whitespace issue in vars file * Attempt to fix integration test failures * Correcting copyright * Addressing initial review comments * Updating decoded sequence return from tuple to list * Correcting capitilization and spelling
This commit is contained in:
parent
d09bc2525b
commit
118d903e7d
7 changed files with 183 additions and 0 deletions
2
tests/integration/targets/filter_hashids/aliases
Normal file
2
tests/integration/targets/filter_hashids/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
|
13
tests/integration/targets/filter_hashids/runme.sh
Executable file
13
tests/integration/targets/filter_hashids/runme.sh
Executable file
|
@ -0,0 +1,13 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -eux
|
||||
|
||||
export ANSIBLE_TEST_PREFER_VENV=1 # see https://github.com/ansible/ansible/pull/73000#issuecomment-757012395; can be removed once Ansible 2.9 and ansible-base 2.10 support has been dropped
|
||||
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 hashids
|
||||
|
||||
ANSIBLE_ROLES_PATH=../ ansible-playbook runme.yml "$@"
|
3
tests/integration/targets/filter_hashids/runme.yml
Normal file
3
tests/integration/targets/filter_hashids/runme.yml
Normal file
|
@ -0,0 +1,3 @@
|
|||
- hosts: localhost
|
||||
roles:
|
||||
- { role: filter_hashids }
|
58
tests/integration/targets/filter_hashids/tasks/main.yml
Normal file
58
tests/integration/targets/filter_hashids/tasks/main.yml
Normal file
|
@ -0,0 +1,58 @@
|
|||
####################################################################
|
||||
# WARNING: These are designed specifically for Ansible tests #
|
||||
# and should not be used as examples of how to write Ansible roles #
|
||||
####################################################################
|
||||
|
||||
- name: Test valid hashable inputs
|
||||
assert:
|
||||
that:
|
||||
- "single_int | community.general.hashids_encode | community.general.hashids_decode == [single_int]"
|
||||
- "int_list | community.general.hashids_encode | community.general.hashids_decode | list == int_list"
|
||||
- "(1,2,3) | community.general.hashids_encode | community.general.hashids_decode == [1,2,3]"
|
||||
|
||||
- name: Test valid parameters
|
||||
assert:
|
||||
that:
|
||||
- "single_int | community.general.hashids_encode(salt='test') | community.general.hashids_decode(salt='test') == [single_int]"
|
||||
- "single_int | community.general.hashids_encode(alphabet='1234567890abcdef') | community.general.hashids_decode(alphabet='1234567890abcdef') == [single_int]"
|
||||
- "single_int | community.general.hashids_encode(min_length=20) | community.general.hashids_decode(min_length=20) == [single_int]"
|
||||
- "single_int | community.general.hashids_encode(min_length=20) | length == 20"
|
||||
|
||||
- name: Test valid unhashable inputs
|
||||
assert:
|
||||
that:
|
||||
- "single_float | community.general.hashids_encode | community.general.hashids_decode == []"
|
||||
- "arbitrary_string | community.general.hashids_encode | community.general.hashids_decode == []"
|
||||
|
||||
- name: Register result of invalid salt
|
||||
debug:
|
||||
var: "invalid_input | community.general.hashids_encode(salt=10)"
|
||||
register: invalid_salt_message
|
||||
ignore_errors: true
|
||||
|
||||
- name: Test invalid salt fails
|
||||
assert:
|
||||
that:
|
||||
- invalid_salt_message is failed
|
||||
|
||||
- name: Register result of invalid alphabet
|
||||
debug:
|
||||
var: "invalid_input | community.general.hashids_encode(alphabet='abc')"
|
||||
register: invalid_alphabet_message
|
||||
ignore_errors: true
|
||||
|
||||
- name: Test invalid alphabet fails
|
||||
assert:
|
||||
that:
|
||||
- invalid_alphabet_message is failed
|
||||
|
||||
- name: Register result of invalid min_length
|
||||
debug:
|
||||
var: "invalid_input | community.general.hashids_encode(min_length='foo')"
|
||||
register: invalid_min_length_message
|
||||
ignore_errors: true
|
||||
|
||||
- name: Test invalid min_length fails
|
||||
assert:
|
||||
that:
|
||||
- invalid_min_length_message is failed
|
4
tests/integration/targets/filter_hashids/vars/main.yml
Normal file
4
tests/integration/targets/filter_hashids/vars/main.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
single_int: 1
|
||||
int_list: [1, 2, 3]
|
||||
single_float: [2.718]
|
||||
arbitrary_string: "will not hash"
|
Loading…
Add table
Add a link
Reference in a new issue