You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansible/test/units
Daniel Goldman 989eeb243f
Add an `undef` global Jinja function (#75435)
* add tests for fail filter

also tests that fail does not block inspectability

* add fail filter

fallback message is a bit clunky,
since you can't invoke a filter without specifying an input.
That is, "{{ fail }}" doesn't work,
so you have to do "{{ None | fail }}"

* document 'fail' filter

* add changelog fragment

* fail filter uses default message on Undefined or emptystring

makes it slightly easier to use the default message:
```diff
- "{{ None | fail }}"
+ "{{ '' | fail }}"
```

and the user sees a slightly more relevant message
if the message itself is undefined:

```diff
- The error was: {{ failmsg | fail }}: 'failmsg' is undefined
+ The error was: {{ failmsg | fail }}: Mandatory variable has not been overridden
```

* rebuild as the builtin `Undefined`

* harmonise `hint` parameter for make_undefined with jinja

* use code block for documentation item

[ref](https://github.com/ansible/ansible/pull/75435#discussion_r707661035)

* rename to `undef` to expose less Python into the Jinja

[ref](https://github.com/ansible/ansible/pull/75435#pullrequestreview-757799031)

* explicitly instantiate undefined value now that it's possible

see I knew we would break something with reflection

* preserve test coverage of undefined variable

Co-authored-by: Matt Davis <nitzmahone@users.noreply.github.com>
3 years ago
..
_vendor Another unit test fix for Python 3.10. (#74628) 3 years ago
ansible_test Remove Shippable CI provider from ansible-test. 3 years ago
cli ansible-cli: Remove unnessary trailing space (#74880) 3 years ago
compat Move unit test compat code out of `lib/ansible/`. (#46996) 6 years ago
config Provide better decryption errors for single vault values (#72362) 4 years ago
errors Fix YAML error message when error is at the end of the file (#73241) 4 years ago
executor Fix up string splitting to prepare for pylint update. (#75479) 3 years ago
galaxy Enable ansible-galaxy to specify client id override with Keycloak Token (#75601) 3 years ago
inventory Clean up unit test boilerplate. 4 years ago
inventory_test_data/group_vars Merge branch 'v2_final' into devel_switch_v2 9 years ago
mock Clean up unit tests to prepare for pylint update. (#75473) 3 years ago
module_utils Ensure `heuristic_log_sanitize` returns correct data if no password found (#75570) 3 years ago
modules pip - Use pip from the current Python interpreter. (#75634) 3 years ago
parsing yaml dumper: Add YAML respresenter for AnsibleUndefined (#75078) 3 years ago
playbook play - validate hosts entries (#74147) 3 years ago
plugins Add an `undef` global Jinja function (#75435) 3 years ago
regex Add toggle to control invalid character substitution in group names (#52748) 6 years ago
template Fix when evaluation on Native Jinja and Python 3.10 (#75202) 3 years ago
utils encrypt: add new paramter 'ident' (#74595) 3 years ago
vars Remove empty setUp/tearDown/tearDownClass methods in test classes. 5 years ago
__init__.py Add empty-init code-smell script. (#18406) 8 years ago
requirements.txt Remove PyCrypto (#74699) 3 years ago
test_constants.py Remove some constants.py deprecated items (#70466) 4 years ago
test_context.py Clean up unit test boilerplate. 4 years ago