summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/win_async_wrapper/library/async_test.ps1
blob: 3b4c1c85f3c4eb38fe351f03af086436409a32b2 (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
#!powershell

# Copyright: (c) 2018, Ansible Project

#Requires -Module Ansible.ModuleUtils.Legacy

$parsed_args = Parse-Args $args

$sleep_delay_sec = Get-AnsibleParam -obj $parsed_args -name "sleep_delay_sec" -type "int" -default 0
$fail_mode = Get-AnsibleParam -obj $parsed_args -name "fail_mode" -type "str" -default "success" -validateset "success", "graceful", "exception"

If ($fail_mode -isnot [array]) {
    $fail_mode = @($fail_mode)
}

$result = @{
    changed = $true
    module_pid = $pid
    module_tempdir = $PSScriptRoot
}

If ($sleep_delay_sec -gt 0) {
    Sleep -Seconds $sleep_delay_sec
    $result["slept_sec"] = $sleep_delay_sec
}

If ($fail_mode -contains "leading_junk") {
    Write-Output "leading junk before module output"
}

If ($fail_mode -contains "graceful") {
    Fail-Json $result "failed gracefully"
}

Try {

    If ($fail_mode -contains "exception") {
        Throw "failing via exception"
    }

    Exit-Json $result
}
Finally {
    If ($fail_mode -contains "trailing_junk") {
        Write-Output "trailing junk after module output"
    }
}