diff options
author | Stephen Ryan <ryaner@users.noreply.github.com> | 2022-02-08 23:19:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-08 23:19:36 +0100 |
commit | 522f9d1050baa3bdea4f3f9df5772c9acdc96f73 (patch) | |
tree | c537300da2489bfb292eea4ad687320c03dd852f /test/integration/targets/file | |
parent | ansible-test - Fix collection loader import. (#76986) (diff) | |
download | ansible-522f9d1050baa3bdea4f3f9df5772c9acdc96f73.tar.xz ansible-522f9d1050baa3bdea4f3f9df5772c9acdc96f73.zip |
Make builtin.file modification times support check_mode (#76973)
* Make builtin.file modification times support check_mode
* Add integration test
Diffstat (limited to 'test/integration/targets/file')
-rw-r--r-- | test/integration/targets/file/tasks/main.yml | 2 | ||||
-rw-r--r-- | test/integration/targets/file/tasks/modification_time.yml | 70 |
2 files changed, 72 insertions, 0 deletions
diff --git a/test/integration/targets/file/tasks/main.yml b/test/integration/targets/file/tasks/main.yml index db56bd2d44..a74cbc289e 100644 --- a/test/integration/targets/file/tasks/main.yml +++ b/test/integration/targets/file/tasks/main.yml @@ -52,6 +52,8 @@ - name: Test _diff_peek import_tasks: diff_peek.yml +- name: Test modification time + import_tasks: modification_time.yml # These tests need to be organized by state parameter into separate files later diff --git a/test/integration/targets/file/tasks/modification_time.yml b/test/integration/targets/file/tasks/modification_time.yml new file mode 100644 index 0000000000..daec03627c --- /dev/null +++ b/test/integration/targets/file/tasks/modification_time.yml @@ -0,0 +1,70 @@ +# file module tests for dealing with modification_time + +- name: Initialize the test output dir + import_tasks: initialize.yml + +- name: Setup the modification time for the tests + set_fact: + modification_timestamp: "202202081414.00" + +- name: Get stat info for the file + stat: + path: "{{ output_file }}" + register: initial_file_stat + +- name: Set a modification time in check_mode + ansible.builtin.file: + path: "{{ output_file }}" + modification_time: "{{ modification_timestamp }}" + modification_time_format: "%Y%m%d%H%M.%S" + check_mode: true + register: file_change_check_mode + +- name: Re-stat the file + stat: + path: "{{ output_file }}" + register: check_mode_stat + +- name: Confirm check_mode did not change the file + assert: + that: + - initial_file_stat.stat.mtime == check_mode_stat.stat.mtime + # Ensure the changed flag was set + - file_change_check_mode.changed + # Ensure the diff is present + # Note: file diff always contains the path + - file_change_check_mode.diff.after | length > 1 + +- name: Set a modification time for real + ansible.builtin.file: + path: "{{ output_file }}" + modification_time: "{{ modification_timestamp }}" + modification_time_format: "%Y%m%d%H%M.%S" + register: file_change_no_check_mode + +- name: Stat of the file after the change + stat: + path: "{{ output_file }}" + register: change_stat + +- name: Confirm the modification time changed + assert: + that: + - initial_file_stat.stat.mtime != change_stat.stat.mtime + - file_change_no_check_mode.changed + # Note: file diff always contains the path + - file_change_no_check_mode.diff.after | length > 1 + +- name: Set a modification time a second time to confirm no changes or diffs + ansible.builtin.file: + path: "{{ output_file }}" + modification_time: "{{ modification_timestamp }}" + modification_time_format: "%Y%m%d%H%M.%S" + register: file_change_no_check_mode_second + +- name: Confirm no changes made registered + assert: + that: + - not file_change_no_check_mode_second.changed + # Note: file diff always contains the path + - file_change_no_check_mode_second.diff.after | length == 1 |