mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-12 00:54:22 -07:00
Add binary_file lookup (#10616)
* Add binary_file lookup. * Remove sentence on deprecation.
This commit is contained in:
parent
4e8a6c03dd
commit
8960a57d53
9 changed files with 187 additions and 0 deletions
5
tests/integration/targets/lookup_binary_file/aliases
Normal file
5
tests/integration/targets/lookup_binary_file/aliases
Normal file
|
@ -0,0 +1,5 @@
|
|||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
azp/posix/2
|
|
@ -0,0 +1 @@
|
|||
file 1
|
|
@ -0,0 +1,3 @@
|
|||
Copyright (c) 2025, Felix Fontein <felix@fontein.de>
|
||||
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
|
@ -0,0 +1 @@
|
|||
file 2
|
|
@ -0,0 +1,3 @@
|
|||
Copyright (c) 2025, Felix Fontein <felix@fontein.de>
|
||||
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
57
tests/integration/targets/lookup_binary_file/tasks/main.yml
Normal file
57
tests/integration/targets/lookup_binary_file/tasks/main.yml
Normal file
|
@ -0,0 +1,57 @@
|
|||
---
|
||||
# Copyright (c) 2025, Felix Fontein <felix@fontein.de>
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
- name: Read some files
|
||||
ansible.builtin.set_fact:
|
||||
file_1: >-
|
||||
{{ query('community.general.binary_file', 'file_1') }}
|
||||
empty: >-
|
||||
{{ query('community.general.binary_file', 'does-not-exist', not_exist='empty') }}
|
||||
empty_str: >-
|
||||
{{ query('community.general.binary_file', 'does-not-exist', not_exist='empty_str') }}
|
||||
multiple: >-
|
||||
{{ query('community.general.binary_file', 'file_1', 'file_2') }}
|
||||
multiple_empty: >-
|
||||
{{ query('community.general.binary_file', 'file_1', 'does-not-exist', 'file_2', not_exist='empty') }}
|
||||
multiple_empty_str: >-
|
||||
{{ query('community.general.binary_file', 'file_1', 'does-not-exist', 'file_2', not_exist='empty_str') }}
|
||||
|
||||
- name: Check results
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- file_1 == ["file 1" | ansible.builtin.b64encode]
|
||||
- empty == [""]
|
||||
- empty_str == ["empty"]
|
||||
- multiple == ["file 1" | ansible.builtin.b64encode, "file 2" | ansible.builtin.b64encode]
|
||||
- multiple_empty == ["file 1" | ansible.builtin.b64encode, "", "file 2" | ansible.builtin.b64encode]
|
||||
- multiple_empty_str == ["file 1" | ansible.builtin.b64encode, "empty", "file 2" | ansible.builtin.b64encode]
|
||||
|
||||
- name: Fail on non-existing file
|
||||
ansible.builtin.debug:
|
||||
msg: >-
|
||||
{{ query('community.general.binary_file', 'does-not-exist') }}
|
||||
ignore_errors: true
|
||||
register: result
|
||||
|
||||
- name: Check results
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- result is failed
|
||||
- >-
|
||||
"Could not locate file in community.general.binary_file lookup: does-not-exist" in result.msg
|
||||
|
||||
- name: Fail on non-existing file after some existing ones
|
||||
ansible.builtin.debug:
|
||||
msg: >-
|
||||
{{ query('community.general.binary_file', 'file_1', 'does-not-exist', 'file_2') }}
|
||||
ignore_errors: true
|
||||
register: result
|
||||
|
||||
- name: Check results
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- result is failed
|
||||
- >-
|
||||
"Could not locate file in community.general.binary_file lookup: does-not-exist" in result.msg
|
Loading…
Add table
Add a link
Reference in a new issue