Debian Codegraph @

ansible_collections/community/general/tests/integration/targets/lookup_random_string/test.yml

raw
1 ---
2 # Copyright (c) Ansible Project
3 # GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
4 # SPDX-License-Identifier: GPL-3.0-or-later
5
6 - hosts: localhost
7 gather_facts: false
8 tasks:
9 - name: Call plugin
10 set_fact:
11 result1: "{{ query('community.general.random_string') }}"
12 result2: "{{ query('community.general.random_string', length=0) }}"
13 result3: "{{ query('community.general.random_string', length=10) }}"
14 result4: "{{ query('community.general.random_string', length=-1) }}"
15 result5: "{{ query('community.general.random_string', override_special='_', min_special=1) }}"
16 result6: "{{ query('community.general.random_string', upper=false, special=false) }}" # lower case only
17 result7: "{{ query('community.general.random_string', lower=false, special=false) }}" # upper case only
18 result8: "{{ query('community.general.random_string', lower=false, upper=false, special=false) }}" # number only
19 result9: "{{ query('community.general.random_string', lower=false, upper=false, special=false, min_numeric=1, length=1) }}" # single digit only
20 result10: "{{ query('community.general.random_string', numbers=false, upper=false, special=false, min_lower=1, length=1) }}" # single lowercase character only
21 result11: "{{ query('community.general.random_string', base64=true, length=8) }}"
22 result12: "{{ query('community.general.random_string', upper=false, numbers=false, special=false) }}" # all lower case
23 result13: "{{ query('community.general.random_string', override_all='0', length=2) }}"
24 result14: "{{ query('community.general.random_string', seed='1234') }}"
25 result15: "{{ query('community.general.random_string', seed='1234') }}"
26
27 - name: Raise error when impossible constraints are provided
28 set_fact:
29 impossible: "{{ query('community.general.random_string', upper=false, lower=false, special=false, numbers=false) }}"
30 ignore_errors: true
31 register: impossible_result
32
33 - name: Check results
34 assert:
35 that:
36 - result1[0] | length == 8
37 - result2[0] | length == 0
38 - result3[0] | length == 10
39 - result4[0] | length == 0
40 - result5[0] | length == 8
41 - "'_' in result5[0]"
42 - result6[0] is lower
43 - result7[0] is upper
44 - result8[0] | regex_replace('^(\d+)$', '') == ''
45 - result9[0] | regex_replace('^(\d+)$', '') == ''
46 - result9[0] | length == 1
47 - result10[0] | length == 1
48 - result10[0] is lower
49 # if input string is not multiple of 3, base64 encoded string will be padded with =
50 - result11[0].endswith('=')
51 - result12[0] is lower
52 - result13[0] | length == 2
53 - result13[0] == '00'
54 - impossible_result is failed
55 - "'Available characters cannot' in impossible_result.msg"
56 - result15[0] == result14[0]