1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/test/integration/targets/win_copy/tasks/tests.yml
Jordan Borean 8e40ac54dd win_copy: rewrite with new tests and functionality (#27678)
* win_copy rewrite with new tests and functionality

* minor pep fixes

* Handle UTF-8 filenames in zip

* fix for template

* when zip assemblies are not available in .net revert to old behaviour of copying one by one

* typo fix

* some more typos

* updated logic to correctly handle when new directories can be created

* removed testing file as it is not needed

* updated documentation based on PR
2017-08-18 20:33:37 -07:00

392 lines
12 KiB
YAML

---
- name: fail no source or content
win_copy:
dest: dest
register: fail_no_source_content
failed_when: fail_no_source_content.msg != 'src (or content) and dest are required'
- name: fail content but dest isn't a file, unix ending
win_copy:
content: a
dest: a/
register: fail_dest_not_file_unix
failed_when: fail_dest_not_file_unix.msg != 'dest must be a file if content is defined'
- name: fail content but dest isn't a file, windows ending
win_copy:
content: a
dest: a\
register: fail_dest_not_file_windows
failed_when: fail_dest_not_file_windows.msg != 'dest must be a file if content is defined'
- name: fail to copy a file with parent dir that doesn't exist and filename is set
win_copy:
src: foo.txt
dest: '{{test_win_copy_path}}\missing-dir\foo.txt'
register: fail_missing_parent_dir
failed_when: "'Destination directory ' + test_win_copy_path + '\\missing-dir does not exist' not in fail_missing_parent_dir.msg"
- name: copy with content (check mode)
win_copy:
content: a
dest: '{{test_win_copy_path}}\file'
register: copy_content_check
check_mode: yes
- name: get result of copy with content (check mode)
win_stat:
path: '{{test_win_copy_path}}\file'
register: copy_content_actual_check
- name: assert copy with content (check mode)
assert:
that:
- copy_content_check|changed
- copy_content_check.checksum == '86f7e437faa5a7fce15d1ddcb9eaeaea377667b8'
- copy_content_check.operation == 'file_copy'
- copy_content_check.size == 1
- copy_content_actual_check.stat.exists == False
- name: copy with content
win_copy:
content: a
dest: '{{test_win_copy_path}}\file'
register: copy_content
- name: get result of copy with content
win_stat:
path: '{{test_win_copy_path}}\file'
register: copy_content_actual
- name: assert copy with content
assert:
that:
- copy_content|changed
- copy_content.checksum == '86f7e437faa5a7fce15d1ddcb9eaeaea377667b8'
- copy_content.operation == 'file_copy'
- copy_content.size == 1
- copy_content_actual.stat.exists == True
- copy_content_actual.stat.checksum == '86f7e437faa5a7fce15d1ddcb9eaeaea377667b8'
- name: copy with content (idempotent)
win_copy:
content: a
dest: '{{test_win_copy_path}}\file'
register: copy_content_again
- name: assert copy with content (idempotent)
assert:
that:
- not copy_content_again|changed
- name: copy with content change when missing
win_copy:
content: b
dest: '{{test_win_copy_path}}\file'
force: no
register: copy_content_when_missing
- name: assert copy with content change when missing
assert:
that:
- not copy_content_when_missing|changed
- name: copy single file (check mode)
win_copy:
src: foo.txt
dest: '{{test_win_copy_path}}\foo-target.txt'
register: copy_file_check
check_mode: yes
- name: get result of copy single file (check mode)
win_stat:
path: '{{test_win_copy_path}}\foo-target.txt'
register: copy_file_actual_check
- name: assert copy single file (check mode)
assert:
that:
- copy_file_check|changed
- copy_file_check.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
- copy_file_check.operation == 'file_copy'
- copy_file_check.size == 8
- copy_file_actual_check.stat.exists == False
- name: copy single file
win_copy:
src: foo.txt
dest: '{{test_win_copy_path}}\foo-target.txt'
register: copy_file
- name: get result of copy single file
win_stat:
path: '{{test_win_copy_path}}\foo-target.txt'
register: copy_file_actual
- name: assert copy single file
assert:
that:
- copy_file|changed
- copy_file.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
- copy_file.operation == 'file_copy'
- copy_file.size == 8
- copy_file_actual.stat.exists == True
- copy_file_actual.stat.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
- name: copy single file (idempotent)
win_copy:
src: foo.txt
dest: '{{test_win_copy_path}}\foo-target.txt'
register: copy_file_again
- name: assert copy single file (idempotent)
assert:
that:
- not copy_file_again|changed
- name: copy single file to folder (check mode)
win_copy:
src: foo.txt
dest: '{{test_win_copy_path}}\'
register: copy_file_to_folder_check
check_mode: yes
- name: get result of copy single file to folder (check mode)
win_stat:
path: '{{test_win_copy_path}}\foo.txt'
register: copy_file_to_folder_actual_check
- name: assert copy single file to folder (check mode)
assert:
that:
- copy_file_to_folder_check|changed
- copy_file_to_folder_check.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
- copy_file_to_folder_check.operation == 'file_copy'
- copy_file_to_folder_check.size == 8
- copy_file_to_folder_actual_check.stat.exists == False
- name: copy single file to folder
win_copy:
src: foo.txt
dest: '{{test_win_copy_path}}\'
register: copy_file_to_folder
- name: get result of copy single file to folder
win_stat:
path: '{{test_win_copy_path}}\foo.txt'
register: copy_file_to_folder_actual
- name: assert copy single file to folder
assert:
that:
- copy_file_to_folder|changed
- copy_file_to_folder.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
- copy_file_to_folder.operation == 'file_copy'
- copy_file_to_folder.size == 8
- copy_file_to_folder_actual.stat.exists == True
- copy_file_to_folder_actual.stat.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
- name: copy single file to folder (idempotent)
win_copy:
src: foo.txt
dest: '{{test_win_copy_path}}\'
register: copy_file_to_folder_again
- name: assert copy single file to folder (idempotent)
assert:
that:
- not copy_file_to_folder_again|changed
- name: copy single file to missing folder (check mode)
win_copy:
src: foo.txt
dest: '{{test_win_copy_path}}\missing\'
register: copy_file_to_missing_folder_check
check_mode: yes
- name: get result of copy single file to missing folder (check mode)
win_stat:
path: '{{test_win_copy_path}}\missing\foo.txt'
register: copy_file_to_missing_folder_actual_check
- name: assert copy single file to missing folder (check mode)
assert:
that:
- copy_file_to_missing_folder_check|changed
- copy_file_to_missing_folder_check.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
- copy_file_to_missing_folder_check.operation == 'file_copy'
- copy_file_to_missing_folder_check.size == 8
- copy_file_to_missing_folder_actual_check.stat.exists == False
- name: copy single file to missing folder
win_copy:
src: foo.txt
dest: '{{test_win_copy_path}}\missing\'
register: copy_file_to_missing_folder
- name: get result of copy single file to missing folder
win_stat:
path: '{{test_win_copy_path}}\missing\foo.txt'
register: copy_file_to_missing_folder_actual
- name: assert copy single file to missing folder
assert:
that:
- copy_file_to_missing_folder|changed
- copy_file_to_missing_folder.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
- copy_file_to_missing_folder.operation == 'file_copy'
- copy_file_to_missing_folder.size == 8
- copy_file_to_missing_folder_actual.stat.exists == True
- copy_file_to_missing_folder_actual.stat.checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
- name: copy folder (check mode)
win_copy:
src: files
dest: '{{test_win_copy_path}}\recursive\folder'
register: copy_folder_check
check_mode: yes
- name: get result of copy folder (check mode)
win_stat:
path: '{{test_win_copy_path}}\recursive\folder'
register: copy_folder_actual_check
- name: assert copy folder (check mode)
assert:
that:
- copy_folder_check|changed
- copy_folder_check.operation == 'folder_copy'
- copy_folder_actual_check.stat.exists == False
- name: copy folder
win_copy:
src: files
dest: '{{test_win_copy_path}}\recursive\folder'
register: copy_folder
- name: get result of copy folder
win_find:
paths: '{{test_win_copy_path}}\recursive\folder'
recurse: yes
file_type: directory
register: copy_folder_actual
- name: assert copy folder
assert:
that:
- copy_folder|changed
- copy_folder.operation == 'folder_copy'
- copy_folder_actual.examined == 11 # includes files and folders, the below is the nested order
- copy_folder_actual.matched == 6
- copy_folder_actual.files[0].filename == 'files'
- copy_folder_actual.files[1].filename == 'subdir'
- copy_folder_actual.files[2].filename == 'empty'
- copy_folder_actual.files[3].filename == 'subdir2'
- copy_folder_actual.files[4].filename == 'subdir3'
- copy_folder_actual.files[5].filename == 'subdir4'
- name: copy folder (idempotent)
win_copy:
src: files
dest: '{{test_win_copy_path}}\recursive\folder'
register: copy_folder_again
- name: assert copy folder (idempotent)
assert:
that:
- not copy_folder_again|changed
- name: change the text of a file in the remote source
win_copy:
content: bar.txt
dest: '{{test_win_copy_path}}\recursive\folder\files\foo.txt'
- name: remove folder for test of recursive copy
win_file:
path: '{{test_win_copy_path}}\recursive\folder\files\subdir\subdir2\subdir3\subdir4'
state: absent
- name: copy folder after changes
win_copy:
src: files
dest: '{{test_win_copy_path}}\recursive\folder'
register: copy_folder_after_change
- name: get result of copy folder after changes
win_find:
paths: '{{test_win_copy_path}}\recursive\folder\files'
recurse: yes
patterns: ['foo.txt', 'qux.txt']
register: copy_folder_after_changes_actual
- name: assert copy folder after changes
assert:
that:
- copy_folder_after_change|changed
- copy_folder_after_changes_actual.matched == 2
- copy_folder_after_changes_actual.files[0].checksum == 'b54ba7f5621240d403f06815f7246006ef8c7d43'
- copy_folder_after_changes_actual.files[1].checksum == 'c79a6506c1c948be0d456ab5104d5e753ab2f3e6'
- name: copy folder's contents (check mode)
win_copy:
src: files/
dest: '{{test_win_copy_path}}\recursive-contents\'
register: copy_folder_contents_check
check_mode: yes
- name: get result of copy folder'scontents (check mode)
win_stat:
path: '{{test_win_copy_path}}\recursive-contents'
register: copy_folder_contents_actual_check
- name: assert copy folder's contents (check mode)
assert:
that:
- copy_folder_contents_check|changed
- copy_folder_contents_check.operation == 'folder_copy'
- copy_folder_contents_actual_check.stat.exists == False
- name: copy folder's contents
win_copy:
src: files/
dest: '{{test_win_copy_path}}\recursive-contents\'
register: copy_folder_contents
- name: get result of copy folder
win_find:
paths: '{{test_win_copy_path}}\recursive-contents'
recurse: yes
file_type: directory
register: copy_folder_contents_actual
- name: assert copy folder
assert:
that:
- copy_folder_contents|changed
- copy_folder_contents.operation == 'folder_copy'
- copy_folder_contents_actual.examined == 10 # includes files and folders, the below is the nested order
- copy_folder_contents_actual.matched == 5
- copy_folder_contents_actual.files[0].filename == 'subdir'
- copy_folder_contents_actual.files[1].filename == 'empty'
- copy_folder_contents_actual.files[2].filename == 'subdir2'
- copy_folder_contents_actual.files[3].filename == 'subdir3'
- copy_folder_contents_actual.files[4].filename == 'subdir4'
- name: fail to copy file to a folder
win_copy:
src: foo.txt
dest: '{{test_win_copy_path}}\recursive-contents'
register: fail_file_to_folder
failed_when: "'object at path is already a directory' not in fail_file_to_folder.msg"
- name: fail to copy folder to a file
win_copy:
src: subdir/
dest: '{{test_win_copy_path}}\recursive-contents\foo.txt'
register: fail_folder_to_file
failed_when: "'object at parent directory path is already a file' not in fail_folder_to_file.msg"
- name: remove test folder after local to remote tests
win_file:
path: '{{test_win_copy_path}}'
state: absent