Skip to content

Commit a80ecfd

Browse files
committed
Move test
1 parent 87b8bc4 commit a80ecfd

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

dsc/tests/dsc_functions.tests.ps1

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,35 @@ Describe 'tests for function expressions' {
903903
$out.results[0].result.actualState.output | Should -Be $expected
904904
}
905905

906+
It 'tryGet() function works for: <expression>' -TestCases @(
907+
@{ expression = "[tryGet(createObject('a', 1, 'b', 2), 'a')]"; expected = 1 }
908+
@{ expression = "[tryGet(createObject('a', 1, 'b', 2), 'c')]"; expected = $null }
909+
@{ expression = "[tryGet(createObject('key', 'value'), 'key')]"; expected = 'value' }
910+
@{ expression = "[tryGet(createObject('nested', createObject('x', 10)), 'nested')]"; expected = [pscustomobject]@{ x = 10 } }
911+
@{ expression = "[tryGet(createObject('nested', createObject('x', 10)), 'missing')]"; expected = $null }
912+
@{ expression = "[tryGet(createArray(1,2,3), 0)]"; expected = 1 }
913+
@{ expression = "[tryGet(createArray(1,2,3), 3)]"; expected = $null }
914+
@{ expression = "[tryGet(createArray(1,2,3), -3)]"; expected = $null }
915+
) {
916+
param($expression, $expected)
917+
918+
$escapedExpression = $expression -replace "'", "''"
919+
$config_yaml = @"
920+
`$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
921+
resources:
922+
- name: Echo
923+
type: Microsoft.DSC.Debug/Echo
924+
properties:
925+
output: '$escapedExpression'
926+
"@
927+
$out = $config_yaml | dsc config get -f - | ConvertFrom-Json
928+
if ($expected -is [pscustomobject]) {
929+
($out.results[0].result.actualState.output | Out-String) | Should -BeExactly ($expected | Out-String)
930+
} else {
931+
$out.results[0].result.actualState.output | Should -BeExactly $expected
932+
}
933+
}
934+
906935
It 'uriComponent function works for: <testInput>' -TestCases @(
907936
@{ testInput = 'hello world' }
908937
@{ testInput = '[email protected]' }
@@ -1031,33 +1060,4 @@ Describe 'tests for function expressions' {
10311060
$out = $config_yaml | dsc config get -f - | ConvertFrom-Json
10321061
$out.results[0].result.actualState.output | Should -BeExactly $expected
10331062
}
1034-
1035-
It 'tryGet() function works for: <expression>' -TestCases @(
1036-
@{ expression = "[tryGet(createObject('a', 1, 'b', 2), 'a')]"; expected = 1 }
1037-
@{ expression = "[tryGet(createObject('a', 1, 'b', 2), 'c')]"; expected = $null }
1038-
@{ expression = "[tryGet(createObject('key', 'value'), 'key')]"; expected = 'value' }
1039-
@{ expression = "[tryGet(createObject('nested', createObject('x', 10)), 'nested')]"; expected = [pscustomobject]@{ x = 10 } }
1040-
@{ expression = "[tryGet(createObject('nested', createObject('x', 10)), 'missing')]"; expected = $null }
1041-
@{ expression = "[tryGet(createArray(1,2,3), 0)]"; expected = 1 }
1042-
@{ expression = "[tryGet(createArray(1,2,3), 3)]"; expected = $null }
1043-
@{ expression = "[tryGet(createArray(1,2,3), -3)]"; expected = $null }
1044-
) {
1045-
param($expression, $expected)
1046-
1047-
$escapedExpression = $expression -replace "'", "''"
1048-
$config_yaml = @"
1049-
`$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
1050-
resources:
1051-
- name: Echo
1052-
type: Microsoft.DSC.Debug/Echo
1053-
properties:
1054-
output: '$escapedExpression'
1055-
"@
1056-
$out = $config_yaml | dsc config get -f - | ConvertFrom-Json
1057-
if ($expected -is [pscustomobject]) {
1058-
($out.results[0].result.actualState.output | Out-String) | Should -BeExactly ($expected | Out-String)
1059-
} else {
1060-
$out.results[0].result.actualState.output | Should -BeExactly $expected
1061-
}
1062-
}
10631063
}

0 commit comments

Comments
 (0)