summaryrefslogtreecommitdiff
path: root/test/integration/targets/win_get_url/tasks/tests_url.yml
blob: 539aba6a63cf3455b08e89af584db4beed3fcd84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
- name: download single file (check)
  win_get_url:
    url: https://{{test_win_get_url_host}}
    dest: '{{test_win_get_url_path}}\web.html'
  check_mode: yes
  register: http_download_check

- name: get result of download single file (check)
  win_stat:
    path: '{{test_win_get_url_path}}\web.html'
  register: http_download_result_check

- name: assert download single file (check)
  assert:
    that:
    - http_download_check is not failed
    - http_download_check is changed
    - http_download_check.url
    - http_download_check.dest
    - not http_download_result_check.stat.exists

- name: download single file
  win_get_url:
    url: https://{{test_win_get_url_host}}
    dest: '{{test_win_get_url_path}}\web.html'
  register: http_download

- name: get result of download single file
  win_stat:
    path: '{{test_win_get_url_path}}\web.html'
  register: http_download_result

- name: assert download single file
  assert:
    that:
    - http_download is not failed
    - http_download is changed
    - http_download.url
    - http_download.dest
    - http_download_result.stat.exists

- name: download single file (idempotent)
  win_get_url:
    url: https://{{test_win_get_url_host}}
    dest: '{{test_win_get_url_path}}\web.html'
  register: http_download_again

- name: assert download single file (idempotent)
  assert:
    that:
    - not http_download_again is changed

- name: download single file with force no
  win_get_url:
    url: https://{{test_win_get_url_host}}
    dest: '{{test_win_get_url_path}}\web.html'
    force: no
  register: http_download_no_force

- name: assert download single file with force no
  assert:
    that:
    - http_download_no_force is not changed

- name: manually change the content and last modified time on FTP source to older datetime
  win_shell: |
    Set-Content -Path '{{test_win_get_url_path}}\web.html' -Value 'abc'
    (Get-Item -Path '{{test_win_get_url_path}}\web.html').LastWriteTime = (Get-Date -Date "01/01/1970")

- name: download newer file with force no
  win_get_url:
    url: https://{{test_win_get_url_host}}
    dest: '{{test_win_get_url_path}}\web.html'
    force: no
  register: http_download_newer_no_force

- name: assert download newer file with force no
  assert:
    that:
    - http_download_newer_no_force is changed

- name: download file to directory
  win_get_url:
    url: https://{{test_win_get_url_host}}
    dest: '{{test_win_get_url_path}}'
  register: http_download_to_directory

- name: get result of download to directory
  win_stat:
    path: '{{test_win_get_url_path}}\{{test_win_get_url_host}}'
  register: http_download_to_directory_result

- name: assert download file to directory
  assert:
    that:
    - http_download_to_directory is changed
    - http_download_to_directory_result.stat.exists

- name: download to path with env var
  win_get_url:
    url: https://{{test_win_get_url_host}}
    dest: '%{{test_win_get_url_env_var}}%\http-env.html'
  register: http_download_with_env

- name: get result of download to path with env var
  win_stat:
    path: '{{test_win_get_url_path}}\http-env.html'
  register: http_download_with_env_result

- name: assert download to path with env var
  assert:
    that:
    - http_download_with_env is changed
    - http_download_with_env_result.stat.exists

- name: fail when link returns 404
  win_get_url:
    url: https://{{test_win_get_url_host}}/skynet_module.html
    dest: '{{test_win_get_url_path}}\skynet_module.html'
  ignore_errors: yes
  register: fail_download_404

- name: assert fail when link returns 404
  assert:
    that:
    - fail_download_404 is not changed
    - fail_download_404 is failed
    - fail_download_404.status_code == 404

- name: fail when dest is an invalid path
  win_get_url:
    url: https://{{test_win_get_url_host}}
    dest: Q:\Filez\Cyberdyne.html
  register: fail_invalid_path
  failed_when: '"The path ''Q:\Filez'' does not exist for destination ''Q:\Filez\Cyberdyne.html''" not in fail_invalid_path.msg'