1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Update tests for win_get_url module to test force parameter and invalid URLs/paths.

This commit is contained in:
Chris Church 2015-07-10 15:54:18 -04:00
parent 7c73e9c12e
commit 1aa2191fd5
2 changed files with 76 additions and 7 deletions

View file

@ -0,0 +1,7 @@
---
test_win_get_url_link: http://docs.ansible.com
test_win_get_url_path: "C:\\Users\\{{ansible_ssh_user}}\\docs_index.html"
test_win_get_url_invalid_link: http://docs.ansible.com/skynet_module.html
test_win_get_url_invalid_path: "Q:\\Filez\\Cyberdyne.html"
test_win_get_url_dir_path: "C:\\Users\\{{ansible_ssh_user}}"

View file

@ -17,19 +17,81 @@
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: remove test file if it exists
raw: PowerShell -Command {Remove-Item "C:\Users\Administrator\win_get_url.jpg" -Force}
raw: >
PowerShell -Command Remove-Item "{{test_win_get_url_path}}" -Force
ignore_errors: true
- name: test win_get_url module
win_get_url: url=http://placehold.it/10x10.jpg dest='C:\Users\Administrator\win_get_url.jpg'
win_get_url:
url: "{{test_win_get_url_link}}"
dest: "{{test_win_get_url_path}}"
register: win_get_url_result
- name: check win_get_url result
- name: check that url was downloaded
assert:
that:
- "not win_get_url_result|failed"
- "win_get_url_result|changed"
- "win_get_url_result.win_get_url.url"
- "win_get_url_result.win_get_url.dest"
# FIXME:
# - Test invalid url
# - Test invalid dest, when dest is directory
# - Test idempotence when downloading same url/dest (not yet implemented)
- name: test win_get_url module again (force should be yes by default)
win_get_url:
url: "{{test_win_get_url_link}}"
dest: "{{test_win_get_url_path}}"
register: win_get_url_result_again
- name: check that url was downloaded again
assert:
that:
- "not win_get_url_result_again|failed"
- "win_get_url_result_again|changed"
- name: test win_get_url module again with force=no
win_get_url:
url: "{{test_win_get_url_link}}"
dest: "{{test_win_get_url_path}}"
force: no
register: win_get_url_result_noforce
- name: check that url was not downloaded again
assert:
that:
- "not win_get_url_result_noforce|failed"
- "not win_get_url_result_noforce|changed"
- name: test win_get_url module with url that returns a 404
win_get_url:
url: "{{test_win_get_url_invalid_link}}"
dest: "{{test_win_get_url_path}}"
register: win_get_url_result_invalid_link
ignore_errors: true
- name: check that the download failed for an invalid url
assert:
that:
- "win_get_url_result_invalid_link|failed"
- name: test win_get_url module with an invalid path
win_get_url:
url: "{{test_win_get_url_link}}"
dest: "{{test_win_get_url_invalid_path}}"
register: win_get_url_result_invalid_path
ignore_errors: true
- name: check that the download failed for an invalid path
assert:
that:
- "win_get_url_result_invalid_path|failed"
- name: test win_get_url module with a valid path that is a directory
win_get_url:
url: "{{test_win_get_url_link}}"
dest: "{{test_win_get_url_dir_path}}"
register: win_get_url_result_dir_path
ignore_errors: true
- name: check that the download failed if dest is a directory
assert:
that:
- "win_get_url_result_dir_path|failed"