Debian Codegraph @

test/integration/targets/win_async_wrapper/library/async_test.ps1

raw
1 #!powershell
2
3 # Copyright: (c) 2018, Ansible Project
4
5 #Requires -Module Ansible.ModuleUtils.Legacy
6
7 $parsed_args = Parse-Args $args
8
9 $sleep_delay_sec = Get-AnsibleParam -obj $parsed_args -name "sleep_delay_sec" -type "int" -default 0
10 $fail_mode = Get-AnsibleParam -obj $parsed_args -name "fail_mode" -type "str" -default "success" -validateset "success", "graceful", "exception"
11
12 If ($fail_mode -isnot [array]) {
13 $fail_mode = @($fail_mode)
14 }
15
16 $result = @{
17 changed = $true
18 module_pid = $pid
19 module_tempdir = $PSScriptRoot
20 }
21
22 If ($sleep_delay_sec -gt 0) {
23 Sleep -Seconds $sleep_delay_sec
24 $result["slept_sec"] = $sleep_delay_sec
25 }
26
27 If ($fail_mode -contains "leading_junk") {
28 Write-Output "leading junk before module output"
29 }
30
31 If ($fail_mode -contains "graceful") {
32 Fail-Json $result "failed gracefully"
33 }
34
35 Try {
36
37 If ($fail_mode -contains "exception") {
38 Throw "failing via exception"
39 }
40
41 Exit-Json $result
42 }
43 Finally {
44 If ($fail_mode -contains "trailing_junk") {
45 Write-Output "trailing junk after module output"
46 }
47 }