From bb947d129bb1b2fc5c7434005df070a8978c3760 Mon Sep 17 00:00:00 2001 From: Simon Leary Date: Fri, 15 Nov 2024 05:24:03 +0000 Subject: [PATCH] add tests --- .../targets/file/files/diff-test/file | 0 .../targets/file/tasks/directory_as_dest.yml | 45 +++++++++++++++++++ test/integration/targets/file/tasks/main.yml | 19 ++++++++ 3 files changed, 64 insertions(+) create mode 100644 test/integration/targets/file/files/diff-test/file diff --git a/test/integration/targets/file/files/diff-test/file b/test/integration/targets/file/files/diff-test/file new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/integration/targets/file/tasks/directory_as_dest.yml b/test/integration/targets/file/tasks/directory_as_dest.yml index 161a12a4bea..bfdf305692b 100644 --- a/test/integration/targets/file/tasks/directory_as_dest.yml +++ b/test/integration/targets/file/tasks/directory_as_dest.yml @@ -23,6 +23,51 @@ dest: '{{remote_tmp_dir_test}}/file_to_link' content: 'Hello World' +# +# edge cases that came up in the `copy` integration tests but not `file` +# + +- name: create a new directory with a relative destination path + file: + path: "{{ lookup('password', '/dev/null', length=10) }}" + state: directory + register: relative_temp_dir + +- name: create a new directory with a destination path that ends in a slash + file: + path: '{{ remote_tmp_dir_test }}/ends_with_slash/' + state: directory + +- name: cleanup + file: + path: "{{ item }}" + state: absent + loop: + - '{{ relative_temp_dir.path }}' + - '{{ remote_tmp_dir_test }}/ends_with_slash/' + +# +# verify diff output +# + +- name: make a directory and its parent directory + file: + path: "{{ remote_tmp_dir }}/foo/bar" + state: directory + diff: true + register: make_2_dirs + +- name: assert that both foo and foo/bar have their own diffs + assert: + that: + - (make_2_dirs.diff | length) == 2 + - (make_2_dirs.diff | map(attribute='after') | map(attribute='path') | sort) == ["{{ remote_tmp_dir }}/foo", "{{ remote_tmp_dir }}/foo/bar"] + +- name: cleanup + file: + path: "{{ remote_tmp_dir }}/foo" + state: absent + # # Error condtion: specify a directory with state={link,file}, force=False # diff --git a/test/integration/targets/file/tasks/main.yml b/test/integration/targets/file/tasks/main.yml index 8e14618118f..328ded877ee 100644 --- a/test/integration/targets/file/tasks/main.yml +++ b/test/integration/targets/file/tasks/main.yml @@ -397,6 +397,25 @@ - name: change the ownership of a directory with recurse=yes file: path={{remote_tmp_dir_test}}/foobar owner=1235 recurse=yes +- name: copy directory for diff test + copy: + src: diff-test + dest: "{{remote_tmp_dir_test}}/" + owner: 1234 + +- name: change the owner on the diff test files + file: + path: "{{remote_tmp_dir_test}}/diff-test" + owner: 1235 + recurse: true + register: change_ownership_recurse + +- name: verify that both the directory and the file have diffs + assert: + that: + - (change_ownership_recurse.diff | length) == 2 + - (change_ownership_recurse.diff | map(attribute='after') | map(attribute='path') | sort) == ["{{remote_tmp_dir_test}}/diff-test", "{{remote_tmp_dir_test}}/diff-test/file"] + - name: verify that the permission of the directory was set file: path={{remote_tmp_dir_test}}/foobar state=directory register: file10_result