diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 16:04:21 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 16:04:21 +0000 |
commit | 8a754e0858d922e955e71b253c139e071ecec432 (patch) | |
tree | 527d16e74bfd1840c85efd675fdecad056c54107 /test/integration/targets/win_exec_wrapper/library/test_common_functions.ps1 | |
parent | Initial commit. (diff) | |
download | ansible-core-upstream.tar.xz ansible-core-upstream.zip |
Adding upstream version 2.14.3.upstream/2.14.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/integration/targets/win_exec_wrapper/library/test_common_functions.ps1')
-rw-r--r-- | test/integration/targets/win_exec_wrapper/library/test_common_functions.ps1 | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/test/integration/targets/win_exec_wrapper/library/test_common_functions.ps1 b/test/integration/targets/win_exec_wrapper/library/test_common_functions.ps1 new file mode 100644 index 0000000..dde1ebc --- /dev/null +++ b/test/integration/targets/win_exec_wrapper/library/test_common_functions.ps1 @@ -0,0 +1,43 @@ +#!powershell + +#Requires -Module Ansible.ModuleUtils.Legacy + +$ErrorActionPreference = "Stop" + +Function Assert-Equal($actual, $expected) { + if ($actual -cne $expected) { + $call_stack = (Get-PSCallStack)[1] + $error_msg = -join @( + "AssertionError:`r`nActual: `"$actual`" != Expected: `"$expected`"`r`nLine: " + "$($call_stack.ScriptLineNumber), Method: $($call_stack.Position.Text)" + ) + Fail-Json -obj $result -message $error_msg + } +} + +$result = @{ + changed = $false +} + +#ConvertFrom-AnsibleJso +$input_json = '{"string":"string","float":3.1415926,"dict":{"string":"string","int":1},"list":["entry 1","entry 2"],"null":null,"int":1}' +$actual = ConvertFrom-AnsibleJson -InputObject $input_json +Assert-Equal -actual $actual.GetType() -expected ([Hashtable]) +Assert-Equal -actual $actual.string.GetType() -expected ([String]) +Assert-Equal -actual $actual.string -expected "string" +Assert-Equal -actual $actual.int.GetType() -expected ([Int32]) +Assert-Equal -actual $actual.int -expected 1 +Assert-Equal -actual $actual.null -expected $null +Assert-Equal -actual $actual.float.GetType() -expected ([Decimal]) +Assert-Equal -actual $actual.float -expected 3.1415926 +Assert-Equal -actual $actual.list.GetType() -expected ([Object[]]) +Assert-Equal -actual $actual.list.Count -expected 2 +Assert-Equal -actual $actual.list[0] -expected "entry 1" +Assert-Equal -actual $actual.list[1] -expected "entry 2" +Assert-Equal -actual $actual.GetType() -expected ([Hashtable]) +Assert-Equal -actual $actual.dict.string -expected "string" +Assert-Equal -actual $actual.dict.int -expected 1 + +$result.msg = "good" +Exit-Json -obj $result + |