2014-06-19 18:32:43 +00:00
|
|
|
# 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/>.
|
|
|
|
|
2017-08-29 00:11:10 +00:00
|
|
|
- setup:
|
2016-05-17 20:40:40 +00:00
|
|
|
|
2017-08-29 00:11:10 +00:00
|
|
|
- name: Remove test file if it exists
|
|
|
|
win_file:
|
|
|
|
path: '{{ test_win_get_url_path }}'
|
|
|
|
state: absent
|
2014-06-19 18:32:43 +00:00
|
|
|
|
2017-08-29 00:11:10 +00:00
|
|
|
- name: Test win_get_url module
|
2015-07-10 19:54:18 +00:00
|
|
|
win_get_url:
|
2017-08-29 00:11:10 +00:00
|
|
|
url: '{{ test_win_get_url_link }}'
|
|
|
|
dest: '{{ test_win_get_url_path }}'
|
2014-06-19 18:32:43 +00:00
|
|
|
register: win_get_url_result
|
|
|
|
|
2017-08-29 00:11:10 +00:00
|
|
|
- name: Check that url was downloaded
|
2016-04-18 14:47:38 +00:00
|
|
|
assert:
|
2014-06-19 18:32:43 +00:00
|
|
|
that:
|
2017-08-29 00:11:10 +00:00
|
|
|
- not win_get_url_result|failed
|
|
|
|
- win_get_url_result|changed
|
|
|
|
- win_get_url_result.url
|
|
|
|
- win_get_url_result.dest
|
2014-06-19 18:32:43 +00:00
|
|
|
|
2017-08-29 00:11:10 +00:00
|
|
|
- name: Test win_get_url module again (force should be yes by default)
|
2015-07-10 19:54:18 +00:00
|
|
|
win_get_url:
|
2017-08-29 00:11:10 +00:00
|
|
|
url: '{{ test_win_get_url_link }}'
|
|
|
|
dest: '{{ test_win_get_url_path }}'
|
2015-07-10 19:54:18 +00:00
|
|
|
register: win_get_url_result_again
|
|
|
|
|
2017-08-29 00:11:10 +00:00
|
|
|
- name: Check that url was downloaded again
|
2016-04-18 14:47:38 +00:00
|
|
|
assert:
|
2015-07-10 19:54:18 +00:00
|
|
|
that:
|
2017-08-29 00:11:10 +00:00
|
|
|
- not win_get_url_result_again|failed
|
|
|
|
- win_get_url_result_again|changed
|
2015-07-10 19:54:18 +00:00
|
|
|
|
2017-08-29 00:11:10 +00:00
|
|
|
- name: Test win_get_url module again with force=no
|
2015-07-10 19:54:18 +00:00
|
|
|
win_get_url:
|
2017-08-29 00:11:10 +00:00
|
|
|
url: '{{ test_win_get_url_link }}'
|
|
|
|
dest: '{{ test_win_get_url_path }}'
|
2015-07-10 19:54:18 +00:00
|
|
|
force: no
|
|
|
|
register: win_get_url_result_noforce
|
|
|
|
|
2017-08-29 00:11:10 +00:00
|
|
|
- name: Check that url was not downloaded again
|
2016-04-18 14:47:38 +00:00
|
|
|
assert:
|
2015-07-10 19:54:18 +00:00
|
|
|
that:
|
2017-08-29 00:11:10 +00:00
|
|
|
- not win_get_url_result_noforce|failed
|
|
|
|
- not win_get_url_result_noforce|changed
|
2015-07-10 19:54:18 +00:00
|
|
|
|
2017-08-29 00:11:10 +00:00
|
|
|
- name: Test win_get_url module with url that returns a 404
|
2015-07-10 19:54:18 +00:00
|
|
|
win_get_url:
|
2017-08-29 00:11:10 +00:00
|
|
|
url: '{{ test_win_get_url_invalid_link }}'
|
|
|
|
dest: '{{ test_win_get_url_path }}'
|
2015-07-10 19:54:18 +00:00
|
|
|
register: win_get_url_result_invalid_link
|
|
|
|
ignore_errors: true
|
|
|
|
|
2017-08-29 00:11:10 +00:00
|
|
|
- name: Check that the download failed for an invalid url
|
2016-04-18 14:47:38 +00:00
|
|
|
assert:
|
2015-07-10 19:54:18 +00:00
|
|
|
that:
|
2017-08-29 00:11:10 +00:00
|
|
|
- win_get_url_result_invalid_link|failed
|
|
|
|
- win_get_url_result_invalid_link.status_code == 404
|
2015-07-10 19:54:18 +00:00
|
|
|
|
2017-08-29 00:11:10 +00:00
|
|
|
- name: Test win_get_url module with an invalid path
|
2015-07-10 19:54:18 +00:00
|
|
|
win_get_url:
|
2017-08-29 00:11:10 +00:00
|
|
|
url: '{{ test_win_get_url_link }}'
|
|
|
|
dest: '{{ test_win_get_url_invalid_path }}'
|
2015-07-10 19:54:18 +00:00
|
|
|
register: win_get_url_result_invalid_path
|
|
|
|
ignore_errors: true
|
|
|
|
|
2017-08-29 00:11:10 +00:00
|
|
|
- name: Check that the download failed for an invalid path
|
2016-04-18 14:47:38 +00:00
|
|
|
assert:
|
2015-07-10 19:54:18 +00:00
|
|
|
that:
|
2017-08-29 00:11:10 +00:00
|
|
|
- win_get_url_result_invalid_path|failed
|
2015-07-10 19:54:18 +00:00
|
|
|
|
2017-08-29 00:11:10 +00:00
|
|
|
- name: Test win_get_url module with a valid path that is a directory
|
2015-07-10 19:54:18 +00:00
|
|
|
win_get_url:
|
2017-08-29 00:11:10 +00:00
|
|
|
url: '{{ test_win_get_url_link }}'
|
|
|
|
dest: '%TEMP%'
|
2015-07-10 19:54:18 +00:00
|
|
|
register: win_get_url_result_dir_path
|
|
|
|
ignore_errors: true
|
|
|
|
|
2017-08-29 00:11:10 +00:00
|
|
|
- name: Check that the download did NOT fail, even though dest was directory
|
2016-04-18 14:47:38 +00:00
|
|
|
assert:
|
2015-07-10 19:54:18 +00:00
|
|
|
that:
|
2017-08-29 00:11:10 +00:00
|
|
|
- win_get_url_result_dir_path|changed
|
2017-07-10 04:30:55 +00:00
|
|
|
|
2017-08-29 00:11:10 +00:00
|
|
|
- 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)
|
2017-07-10 04:30:55 +00:00
|
|
|
win_get_url:
|
2017-08-29 00:11:10 +00:00
|
|
|
url: '{{ test_win_get_url_link }}'
|
|
|
|
dest: '%TEMP%'
|
2017-07-10 04:30:55 +00:00
|
|
|
register: win_get_url_result_dir_path_urlpath
|
|
|
|
ignore_errors: true
|
|
|
|
|
2017-08-29 00:11:10 +00:00
|
|
|
- name: Set expected destination path fact
|
2017-07-10 04:30:55 +00:00
|
|
|
set_fact:
|
2017-08-29 00:11:10 +00:00
|
|
|
expected_dest_path: '{{ ansible_env.TEMP }}\{{ test_win_get_url_host }}'
|
2017-07-10 04:30:55 +00:00
|
|
|
|
2017-08-29 00:11:10 +00:00
|
|
|
- name: Check that the download succeeded (changed) and dest is as expected
|
2017-07-10 04:30:55 +00:00
|
|
|
assert:
|
|
|
|
that:
|
2017-08-29 00:11:10 +00:00
|
|
|
- win_get_url_result_dir_path_urlpath|changed
|
|
|
|
- win_get_url_result_dir_path_urlpath.dest == expected_dest_path
|
|
|
|
|
|
|
|
- name: Check you get a helpful message if the parent folder of the dest doesn't exist
|
|
|
|
win_get_url:
|
|
|
|
url: '{{ test_win_get_url_link }}'
|
|
|
|
dest: 'Q:\Filez\'
|
|
|
|
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
|
2017-09-14 01:18:32 +00:00
|
|
|
- win_get_url_result_invalid_dest.msg is search('does not exist, or is not visible to the current user')
|
2017-08-29 00:11:10 +00:00
|
|
|
|
|
|
|
- name: Check you get a helpful message if the parent folder of the dest doesn't exist
|
|
|
|
win_get_url:
|
|
|
|
url: '{{ test_win_get_url_link }}'
|
|
|
|
dest: 'C:\Filez\'
|
|
|
|
register: win_get_url_result_invalid_dest2
|
|
|
|
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_dest2|failed
|
|
|
|
- win_get_url_result_invalid_dest2.msg is search('does not exist')
|