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_get_url/tasks/main.yml

136 lines
4.3 KiB
YAML
Raw Normal View History

# test code for the win_get_url module
# (c) 2014, Chris Church <chris@ninemoreminutes.com>
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
- name: get tempdir path
raw: $env:TEMP
register: tempdir
- name: set output path dynamically
set_fact:
test_win_get_url_dir_path: "{{ tempdir.stdout_lines[0] }}"
- name: remove test file if it exists
raw: >
PowerShell -Command Remove-Item "{{test_win_get_url_path}}" -Force
ignore_errors: true
- name: test win_get_url module
win_get_url:
url: "{{test_win_get_url_link}}"
dest: "{{test_win_get_url_path}}"
register: 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"
- 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 did NOT fail, even though dest was directory
assert:
that:
- "win_get_url_result_dir_path|changed"
- name: test win_get_url with a valid url path and a dest that is a directory (from 2.4 should use url path as filename)
win_get_url:
url: "{{test_win_get_url_link}}"
dest: "{{test_win_get_url_dir_path}}"
register: win_get_url_result_dir_path_urlpath
ignore_errors: true
- name: set expected destination path fact
set_fact:
expected_dest_path: '{{test_win_get_url_dir_path}}\{{test_win_get_url_host}}'
- name: check that the download succeeded (changed) and dest is as expected
assert:
that:
- "win_get_url_result_dir_path_urlpath|changed"
- "win_get_url_result_dir_path_urlpath.win_get_url.actual_dest==expected_dest_path"
#- name: since 2.4 check you get a helpful message if the parent folder of the dest doesnt exist
# win_get_url:
# url: "{{test_win_get_url_link}}"
# dest: "{{test_win_get_url_invalid_path_dir}}"
# register: win_get_url_result_invalid_dest
# ignore_errors: true
#
#- name: check if dest parent dir does not exist, module fails and you get a specific error message
# assert:
# that:
# - "win_get_url_result_invalid_dest|failed"
# - "win_get_url_result_invalid_dest.msg is search('does not exist')"