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

win_shortcut: Add missing $check_mode definition + bugfix + tests (#20911)

* win_shortcut: Add missing $check_mode definition

For some reason this entry was missing, possible a merge-conflict gone
wrong :-(

* Added integration tests and bugfix

Add missing changes.
This commit is contained in:
Dag Wieers 2017-02-02 10:29:56 +01:00 committed by John R Barker
parent afe29977cb
commit 3dbce15ccb
4 changed files with 167 additions and 0 deletions

View file

@ -24,6 +24,7 @@
$ErrorActionPreference = "Stop" $ErrorActionPreference = "Stop"
$params = Parse-Args $args -supports_check_mode $true $params = Parse-Args $args -supports_check_mode $true
$check_mode = Get-AnsibleParam -obj $params -name "_ansible_check_mode" -type "bool" -default $false
$src = Get-AnsibleParam -obj $params -name "src" -type "path" -default $null $src = Get-AnsibleParam -obj $params -name "src" -type "path" -default $null
$dest = Get-AnsibleParam -obj $params -name "dest" -type "path" -failifempty $true $dest = Get-AnsibleParam -obj $params -name "dest" -type "path" -failifempty $true
@ -78,6 +79,13 @@ If ($state -eq "absent") {
# Compare existing values with new values, report as changed if required # Compare existing values with new values, report as changed if required
If ($src -ne $null) {
# Windows translates executables to absolute path, so do we
If (Get-Command -Name $src -Type Application -ErrorAction SilentlyContinue) {
$src = (Get-Command -Name $src -Type Application).Definition
}
}
If ($src -ne $null -and $ShortCut.TargetPath -ne $src) { If ($src -ne $null -and $ShortCut.TargetPath -ne $src) {
$result.changed = $true $result.changed = $true
$ShortCut.TargetPath = $src $ShortCut.TargetPath = $src

View file

@ -0,0 +1 @@
windows/ci/group2

View file

@ -0,0 +1,157 @@
- name: Clean up Ansible website link
win_file:
path: '%UserProfile%\Desktop\Ansible website.url'
state: absent
- name: Add Ansible website link on the desktop
win_shortcut:
src: 'https://ansible.com/'
dest: '%UserProfile%\Desktop\Ansible website.url'
state: present
register: ansible_website_link_add
- name: Check there was a change
assert:
that:
- ansible_website_link_add.changed == true
- name: Add Ansible website link on the desktop again
win_shortcut:
src: 'https://ansible.com/'
dest: '%UserProfile%\Desktop\Ansible website.url'
state: present
register: ansible_website_link_add_again
- name: Check there was no change
assert:
that:
- ansible_website_link_add_again.changed == false
- name: Remove link
win_shortcut:
dest: '%UserProfile%\Desktop\Ansible website.url'
state: absent
register: ansible_website_link_remove
- name: Check there was a change
assert:
that:
- ansible_website_link_remove.changed == true
- name: Remove link again
win_shortcut:
dest: '%UserProfile%\Desktop\Ansible website.url'
state: absent
register: ansible_website_link_remove_again
- name: Check there was no change
assert:
that:
- ansible_website_link_remove_again.changed == false
- name: Clean up Registry Editor shortcut
win_file:
path: '%Public%\Desktop\Registry Editor.lnk'
state: absent
- name: Add a regedit shortcut on the desktop
win_shortcut:
description: "Registry Editor"
src: regedit.exe
dest: '%Public%\Desktop\Registry Editor.lnk'
state: present
register: regedit_shortcut_add
- name: Check there was a change
assert:
that:
- regedit_shortcut_add.changed == true
- name: Add a regedit shortcut on the desktop again
win_shortcut:
description: "Registry Editor"
src: regedit.exe
dest: '%Public%\Desktop\Registry Editor.lnk'
state: present
register: regedit_shortcut_add_again
- name: Check there was no change
assert:
that:
- regedit_shortcut_add_again.changed == false
- name: Update a regedit shortcut on the desktop
win_shortcut:
description: "Registry Editor"
src: C:\BogusPath\regedit.exe
dest: '%Public%\Desktop\Registry Editor.lnk'
state: present
register: regedit_shortcut_update
- name: Check there was a change
assert:
that:
- regedit_shortcut_update.changed == true
- name: Update a regedit shortcut on the desktop again
win_shortcut:
description: "Registry Editor"
src: C:\BogusPath\regedit.exe
dest: '%Public%\Desktop\Registry Editor.lnk'
state: present
register: regedit_shortcut_update_again
- name: Check there was no change
assert:
that:
- regedit_shortcut_update_again.changed == false
- name: Add an (explicit) icon
win_shortcut:
description: "Registry Editor"
src: C:\Windows\regedit.exe
dest: '%Public%\Desktop\Registry Editor.lnk'
icon: 'C:\Windows\regedit.exe,0'
state: present
register: regedit_shortcut_add_icon
- name: Check there was a change
assert:
that:
- regedit_shortcut_add_icon.changed == true
- name: Add an (explicit) icon again
win_shortcut:
description: "Registry Editor"
src: C:\Windows\regedit.exe
dest: '%Public%\Desktop\Registry Editor.lnk'
icon: 'C:\Windows\regedit.exe,0'
state: present
register: regedit_shortcut_add_icon_again
- name: Check there was no change
assert:
that:
- regedit_shortcut_add_icon_again.changed == false
- name: Remove shortcut
win_shortcut:
dest: '%Public%\Desktop\Registry Editor.lnk'
state: absent
register: regedit_shortcut_remove
- name: Check there was a change
assert:
that:
- regedit_shortcut_remove.changed == true
- name: Remove shortcut again
win_shortcut:
dest: '%Public%\Desktop\Registry Editor.lnk'
state: absent
register: regedit_shortcut_remove_again
- name: Check there was no change
assert:
that:
- regedit_shortcut_remove_again.changed == false

View file

@ -11,3 +11,4 @@
- { role: win_msi, tags: test_win_msi } - { role: win_msi, tags: test_win_msi }
- { role: win_package, tags: test_win_package } - { role: win_package, tags: test_win_package }
- { role: win_path, tags: test_win_path } - { role: win_path, tags: test_win_path }
- { role: win_shortcut, tags: test_win_shortcut }