mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-02-04 07:51:50 +00:00
* Add New Module file_remove * Add fixes from code review * Change file_type documentation * Remove python to_native from the module * Remove redundant block/always cleanup * Update plugins/modules/file_remove.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/file_remove.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/file_remove.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/file_remove.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/file_remove.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/file_remove.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/file_remove.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/file_remove.py Co-authored-by: Felix Fontein <felix@fontein.de> * Add more nox fixes to latest review * Update plugins/modules/file_remove.py LGTM Co-authored-by: Felix Fontein <felix@fontein.de> * Update tests/integration/targets/file_remove/tasks/main.yml Right, that's better. Co-authored-by: Felix Fontein <felix@fontein.de> * Fix EXAMPLES regex pattern * Add warning when listed file was removed by other process during playbook execution * remove raise exception from find_matching_files; * Update plugins/modules/file_remove.py Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/file_remove.py Co-authored-by: Felix Fontein <felix@fontein.de> --------- Co-authored-by: Felix Fontein <felix@fontein.de>
57 lines
1.5 KiB
YAML
57 lines
1.5 KiB
YAML
---
|
|
# 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
|
|
|
|
# Test error handling
|
|
|
|
- name: Test with non-existent path
|
|
community.general.file_remove:
|
|
path: /this/path/does/not/exist
|
|
pattern: "*.txt"
|
|
register: error_result_1
|
|
ignore_errors: true
|
|
|
|
- name: Verify that non-existent path fails
|
|
ansible.builtin.assert:
|
|
that:
|
|
- error_result_1 is failed
|
|
- "'does not exist' in error_result_1.msg"
|
|
|
|
- name: Create a test file to use as a non-directory path
|
|
ansible.builtin.file:
|
|
path: "{{ file_remove_testdir }}/testfile"
|
|
state: touch
|
|
mode: '0644'
|
|
|
|
- name: Test with a file path instead of directory
|
|
community.general.file_remove:
|
|
path: "{{ file_remove_testdir }}/testfile"
|
|
pattern: "*.txt"
|
|
register: error_result_2
|
|
ignore_errors: true
|
|
|
|
- name: Verify that non-directory path fails
|
|
ansible.builtin.assert:
|
|
that:
|
|
- error_result_2 is failed
|
|
- "'not a directory' in error_result_2.msg"
|
|
|
|
- name: Test with invalid regex pattern
|
|
community.general.file_remove:
|
|
path: "{{ file_remove_testdir }}"
|
|
pattern: "[unclosed"
|
|
use_regex: true
|
|
register: error_result_3
|
|
ignore_errors: true
|
|
|
|
- name: Verify that invalid regex fails
|
|
ansible.builtin.assert:
|
|
that:
|
|
- error_result_3 is failed
|
|
- "'Invalid regular expression' in error_result_3.msg"
|
|
|
|
- name: Remove test file
|
|
ansible.builtin.file:
|
|
path: "{{ file_remove_testdir }}/testfile"
|
|
state: absent
|