tests: Refactor Ansible copy integration tests to be loop driven

This is in anticipation of #1110, which only exhibits inside a with_items:
loop. For this refactor `loop:` is used, to confirm the refactored tests are
still correct. A subsequent commit will change them to with_items.

The content of the files and their SHA1 checksums are unchanged.
pull/1110/head
Alex Willmer 3 months ago
parent 84a4fcdf00
commit ce1accedbc

@ -2,91 +2,90 @@
- name: integration/action/copy.yml - name: integration/action/copy.yml
hosts: test-targets hosts: test-targets
tasks: vars:
- name: Create tiny file sourced_files:
copy: - src: /tmp/copy-tiny-file
dest: /tmp/copy-tiny-file dest: /tmp/copy-tiny-file.out
content: content: this is a tiny file.
this is a tiny file. expected_checksum: f29faa9a6f19a700a941bf2aa5b281643c4ec8a0
delegate_to: localhost - src: /tmp/copy-large-file
run_once: true dest: /tmp/copy-large-file.out
content: "{{ 'x' * 200000 }}"
expected_checksum: 62951f943c41cdd326e5ce2b53a779e7916a820d
inline_files:
- dest: /tmp/copy-tiny-inline-file.out
content: tiny inline content
expected_checksum: b26dd6444595e2bdb342aa0a91721b57478b5029
- dest: /tmp/copy-large-inline-file.out
content: |
{{ 'y' * 200000 }}
expected_checksum: d675f47e467eae19e49032a2cc39118e12a6ee72
- name: Create large file files: "{{ sourced_files + inline_files }}"
tasks:
- name: Create sourced files
copy: copy:
dest: /tmp/copy-large-file dest: "{{ item.src }}"
# Must be larger than Connection.SMALL_SIZE_LIMIT. content: "{{ item.content }}"
content: "{% for x in range(200000) %}x{% endfor %}" mode: u=rw,go=r
loop: "{{ sourced_files }}"
loop_control:
label: "{{ item.src }}"
delegate_to: localhost delegate_to: localhost
run_once: true run_once: true
- name: Cleanup copied files - name: Cleanup lingering destination files
file: file:
path: "{{ item.dest }}"
state: absent state: absent
path: "{{item}}" loop: "{{ files }}"
with_items: loop_control:
- /tmp/copy-tiny-file.out label: "{{ item.dest }}"
- /tmp/copy-large-file.out
- /tmp/copy-tiny-inline-file.out
- /tmp/copy-large-inline-file.out
- name: Copy large file - name: Copy sourced files
copy: copy:
dest: /tmp/copy-large-file.out src: "{{ item.src }}"
src: /tmp/copy-large-file dest: "{{ item.dest }}"
mode: u=rw,go=r
- name: Copy tiny file loop: "{{ sourced_files }}"
copy: loop_control:
dest: /tmp/copy-tiny-file.out label: "{{ item.dest }}"
src: /tmp/copy-tiny-file
- name: Copy tiny inline file - name: Copy inline files
copy: copy:
dest: /tmp/copy-tiny-inline-file.out dest: "{{ item.dest }}"
content: "tiny inline content" content: "{{ item.content }}"
mode: u=rw,go=r
- name: Copy large inline file loop: "{{ inline_files }}"
copy: loop_control:
dest: /tmp/copy-large-inline-file.out label: "{{ item.dest }}"
content: |
{% for x in range(200000) %}y{% endfor %}
# stat results # stat results
- name: Stat copied files - name: Stat copied files
stat: stat:
path: "{{item}}" path: "{{ item.dest }}"
with_items: loop: "{{ files }}"
- /tmp/copy-tiny-file.out loop_control:
- /tmp/copy-large-file.out label: "{{ item.dest }}"
- /tmp/copy-tiny-inline-file.out
- /tmp/copy-large-inline-file.out
register: stat register: stat
- assert: - assert:
that: that:
- stat.results[0].stat.checksum == "f29faa9a6f19a700a941bf2aa5b281643c4ec8a0" - item.stat.checksum == item.item.expected_checksum
- stat.results[1].stat.checksum == "62951f943c41cdd326e5ce2b53a779e7916a820d" quiet: true # Avoid spamming stdout with 400 kB of item.item.content
- stat.results[2].stat.checksum == "b26dd6444595e2bdb342aa0a91721b57478b5029" fail_msg: item={{ item }}
- stat.results[3].stat.checksum == "d675f47e467eae19e49032a2cc39118e12a6ee72" loop: "{{ stat.results }}"
fail_msg: stat={{stat}} loop_control:
label: "{{ item.stat.path }}"
- name: Cleanup files - name: Cleanup destination files
file: file:
path: "{{ item.dest }}"
state: absent state: absent
path: "{{item}}" loop: "{{ files }}"
with_items: loop_control:
- /tmp/copy-tiny-file label: "{{ item.dest }}"
- /tmp/copy-tiny-file.out
- /tmp/copy-no-mode
- /tmp/copy-no-mode.out
- /tmp/copy-with-mode
- /tmp/copy-with-mode.out
- /tmp/copy-large-file
- /tmp/copy-large-file.out
- /tmp/copy-tiny-inline-file.out
- /tmp/copy-large-inline-file
- /tmp/copy-large-inline-file.out
# end of cleaning out files (again)
tags: tags:
- copy - copy

Loading…
Cancel
Save