From 1aa2191fd55a627a1ca867228498d5b1d24ae629 Mon Sep 17 00:00:00 2001 From: Chris Church Date: Fri, 10 Jul 2015 15:54:18 -0400 Subject: [PATCH] Update tests for win_get_url module to test force parameter and invalid URLs/paths. --- .../roles/test_win_get_url/defaults/main.yml | 7 ++ .../roles/test_win_get_url/tasks/main.yml | 76 +++++++++++++++++-- 2 files changed, 76 insertions(+), 7 deletions(-) create mode 100644 test/integration/roles/test_win_get_url/defaults/main.yml diff --git a/test/integration/roles/test_win_get_url/defaults/main.yml b/test/integration/roles/test_win_get_url/defaults/main.yml new file mode 100644 index 0000000000..6e507ecf31 --- /dev/null +++ b/test/integration/roles/test_win_get_url/defaults/main.yml @@ -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}}" diff --git a/test/integration/roles/test_win_get_url/tasks/main.yml b/test/integration/roles/test_win_get_url/tasks/main.yml index 26fb334c95..b0705eabd5 100644 --- a/test/integration/roles/test_win_get_url/tasks/main.yml +++ b/test/integration/roles/test_win_get_url/tasks/main.yml @@ -17,19 +17,81 @@ # along with Ansible. If not, see . - 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"