22# Licensed under the MIT License.
33
44Describe ' Expressions tests' {
5- It ' Accessors work: <text>' - TestCases @ (
6- @ { text = " [parameters('test').hello]" ; expected = ' @{world=there}' }
7- @ { text = " [parameters('test').hello.world]" ; expected = ' there' }
8- @ { text = " [parameters('test').array[0]]" ; expected = ' one' }
9- @ { text = " [parameters('test').array[1][1]]" ; expected = ' three' }
10- @ { text = " [parameters('test').objectArray[0].name]" ; expected = ' one' }
11- @ { text = " [parameters('test').objectArray[1].value[0]]" ; expected = ' 2' }
12- @ { text = " [parameters('test').objectArray[1].value[1].name]" ; expected = ' three' }
13- @ { text = " [parameters('test').index]" ; expected = ' 1' }
14- @ { text = " [parameters('test').objectArray[parameters('test').index].name]" ; expected = ' two' }
15- ) {
16- param ($text , $expected )
17- $yaml = @"
5+ It ' Accessors work: <text>' - TestCases @ (
6+ @ { text = " [parameters('test').hello]" ; expected = ' @{world=there}' }
7+ @ { text = " [parameters('test').hello.world]" ; expected = ' there' }
8+ @ { text = " [parameters('test').array[0]]" ; expected = ' one' }
9+ @ { text = " [parameters('test').array[1][1]]" ; expected = ' three' }
10+ @ { text = " [parameters('test').objectArray[0].name]" ; expected = ' one' }
11+ @ { text = " [parameters('test').objectArray[1].value[0]]" ; expected = ' 2' }
12+ @ { text = " [parameters('test').objectArray[1].value[1].name]" ; expected = ' three' }
13+ @ { text = " [parameters('test').index]" ; expected = ' 1' }
14+ @ { text = " [parameters('test').objectArray[parameters('test').index].name]" ; expected = ' two' }
15+ ) {
16+ param ($text , $expected )
17+ $yaml = @"
1818 `$ schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
1919 parameters:
2020 test:
@@ -40,48 +40,48 @@ Describe 'Expressions tests' {
4040 type: Microsoft.DSC.Debug/Echo
4141 properties:
4242 output: "$text "
43- "@
44- $debug = $yaml | dsc -l trace config get -o yaml -f - 2>&1 | Out-String
45- $out = $yaml | dsc config get -f - | ConvertFrom-Json
46- $LASTEXITCODE | Should -Be 0 -Because $debug
47- $out .results[0].result.actualState.output | Should -Be $expected -Because $debug
48- }
43+ "@
44+ $debug = $yaml | dsc - l trace config get - o yaml -f - 2>&1 | Out-String
45+ $out = $yaml | dsc config get -f - | ConvertFrom-Json
46+ $LASTEXITCODE | Should - Be 0 - Because $debug
47+ $out.results [0 ].result.actualState.output | Should - Be $expected - Because $debug
48+ }
4949
50- It 'Invalid expressions: <expression>' -TestCases @(
51- @{ expression = "[concat('A','B')].hello" }
52- @{ expression = "[concat('A','B')](0)" }
53- @{ expression = "[concat('a','b').hello]" }
54- @{ expression = "[concat('a','b')[0]]" }
55- ) {
56- param($expression )
57- $yaml = @"
50+ It ' Invalid expressions: <expression>' - TestCases @ (
51+ @ { expression = " [concat('A','B')].hello" }
52+ @ { expression = " [concat('A','B')](0)" }
53+ @ { expression = " [concat('a','b').hello]" }
54+ @ { expression = " [concat('a','b')[0]]" }
55+ ) {
56+ param ($expression )
57+ $yaml = @"
5858 `$ schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
5959 resources:
6060 - name: echo
6161 type: Microsoft.DSC.Debug/Echo
6262 properties:
6363 output: "$expression "
64- "@
65- $out = dsc config get -i $yaml 2>&1
66- $LASTEXITCODE | Should -Be 2
67- $out | Should -BeLike "*ERROR*"
68- }
64+ "@
65+ $out = dsc config get - i $yaml 2>&1
66+ $LASTEXITCODE | Should - Be 2
67+ $out | Should - BeLike " *ERROR*"
68+ }
6969
70- It 'Multi-line string literals work' {
71- $yamlPath = "$PSScriptRoot /../examples/multiline.dsc.yaml"
72- $out = dsc config get -f $yamlPath | ConvertFrom-Json
73- $LASTEXITCODE | Should -Be 0
74- $out .results[0].result.actualState.output | Should -BeExactly @"
70+ It ' Multi-line string literals work' {
71+ $yamlPath = " $PSScriptRoot /../examples/multiline.dsc.yaml"
72+ $out = dsc config get -f $yamlPath | ConvertFrom-Json
73+ $LASTEXITCODE | Should - Be 0
74+ $out.results [0 ].result.actualState.output | Should - BeExactly @"
7575 This is a
7676 'multi-line'
7777 string.
7878
79- "@.Replace("`r ", "")
80- $out .results[1].result.actualState.output | Should -BeExactly "This is a single-quote: '"
81- }
79+ "@ .Replace(" `r " , " " )
80+ $out.results [1 ].result.actualState.output | Should - BeExactly " This is a single-quote: '"
81+ }
8282
83- It 'Nested Group resource does not invoke expressions' {
84- $yaml = @'
83+ It ' Nested Group resource does not invoke expressions' {
84+ $yaml = @'
8585 $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
8686 resources:
8787 - name: Nested Group
@@ -101,60 +101,61 @@ Describe 'Expressions tests' {
101101 )]
102102 dependsOn:
103103 - "[resourceId('Microsoft/OSInfo', 'Deeply nested OSInfo')]"
104- '@
104+ '@
105105
106- $out = dsc config get -i $yaml | ConvertFrom-Json
107- $LASTEXITCODE | Should -Be 0
108- $out .results[0].result[1].result.actualState.output.family | Should -BeExactly $out .results[0].result[0].result.actualState.family
109- }
106+ $out = dsc config get - i $yaml | ConvertFrom-Json
107+ $LASTEXITCODE | Should - Be 0
108+ $out.results [0 ].result[1 ].result.actualState.output.family | Should - BeExactly $out.results [0 ].result[0 ].result.actualState.family
109+ }
110110
111- It 'Comparison functions work: <expression>' -TestCases @(
112- @{ expression = "[greater(5, 3)]"; expected = $true }
113- @{ expression = "[greater(3, 5)]"; expected = $false }
114- @{ expression = "[greater(5, 5)]"; expected = $false }
115- @{ expression = "[greaterOrEquals(5, 3)]"; expected = $true }
116- @{ expression = "[greaterOrEquals(3, 5)]"; expected = $false }
117- @{ expression = "[greaterOrEquals(5, 5)]"; expected = $true }
118- @{ expression = "[less(3, 5)]"; expected = $true }
119- @{ expression = "[less(5, 3)]"; expected = $false }
120- @{ expression = "[less(5, 5)]"; expected = $false }
121- @{ expression = "[lessOrEquals(3, 5)]"; expected = $true }
122- @{ expression = "[lessOrEquals(5, 3)]"; expected = $false }
123- @{ expression = "[lessOrEquals(5, 5)]"; expected = $true }
124- @{ expression = "[greater('b', 'a')]"; expected = $true }
125- @{ expression = "[greater('a', 'b')]"; expected = $false }
126- @{ expression = "[greater('A', 'a')]"; expected = $false }
127- @{ expression = "[greaterOrEquals('b', 'a')]"; expected = $true }
128- @{ expression = "[greaterOrEquals('a', 'b')]"; expected = $false }
129- @{ expression = "[greaterOrEquals('a', 'a')]"; expected = $true }
130- @{ expression = "[greaterOrEquals('Aa', 'aa')]"; expected = $false }
131- @{ expression = "[less('a', 'b')]"; expected = $true }
132- @{ expression = "[less('b', 'a')]"; expected = $false }
133- @{ expression = "[less('A', 'a')]"; expected = $true }
134- @{ expression = "[lessOrEquals('a', 'b')]"; expected = $true }
135- @{ expression = "[lessOrEquals('b', 'a')]"; expected = $false }
136- @{ expression = "[lessOrEquals('a', 'a')]"; expected = $true }
137- @{ expression = "[lessOrEquals('aa', 'Aa')]"; expected = $false }
138- @{ expression = "[coalesce('DSC', 'World')]" ; expected = 'DSC' }
139- @{ expression = "[coalesce(42, 'fallback')]" ; expected = 42 }
140- @{ expression = "[coalesce(true, false)]" ; expected = $true }
141- @{ expression = "[coalesce('first', 'second')]" ; expected = 'first' }
142- @{ expression = "[coalesce(createArray('a', 'b'), createArray('c', 'd'))]" ; expected = @('a', 'b') }
143- @{ expression = "[coalesce(null(), 'fallback')]" ; expected = 'fallback' }
144- @{ expression = "[coalesce(null(), createArray(1, 2, 3))]" ; expected = @(1, 2, 3) }
145- @{ expression = "[coalesce(null(), null(), null(), 'finalValue')]" ; expected = 'finalValue' }
146- @{ expression = "[coalesce(null(), 42, 'not-reached')]" ; expected = 42 }
147- @{ expression = "[coalesce(null(), true, false)]" ; expected = $true }
148- ) {
149- param($expression , $expected )
150- $yaml = @"
111+ It ' Comparison functions work: <expression>' - TestCases @ (
112+ @ { expression = " [greater(5, 3)]" ; expected = $true }
113+ @ { expression = " [greater(3, 5)]" ; expected = $false }
114+ @ { expression = " [greater(5, 5)]" ; expected = $false }
115+ @ { expression = " [greaterOrEquals(5, 3)]" ; expected = $true }
116+ @ { expression = " [greaterOrEquals(3, 5)]" ; expected = $false }
117+ @ { expression = " [greaterOrEquals(5, 5)]" ; expected = $true }
118+ @ { expression = " [less(3, 5)]" ; expected = $true }
119+ @ { expression = " [less(5, 3)]" ; expected = $false }
120+ @ { expression = " [less(5, 5)]" ; expected = $false }
121+ @ { expression = " [lessOrEquals(3, 5)]" ; expected = $true }
122+ @ { expression = " [lessOrEquals(5, 3)]" ; expected = $false }
123+ @ { expression = " [lessOrEquals(5, 5)]" ; expected = $true }
124+ @ { expression = " [greater('b', 'a')]" ; expected = $true }
125+ @ { expression = " [greater('a', 'b')]" ; expected = $false }
126+ @ { expression = " [greater('A', 'a')]" ; expected = $false }
127+ @ { expression = " [greaterOrEquals('b', 'a')]" ; expected = $true }
128+ @ { expression = " [greaterOrEquals('a', 'b')]" ; expected = $false }
129+ @ { expression = " [greaterOrEquals('a', 'a')]" ; expected = $true }
130+ @ { expression = " [greaterOrEquals('Aa', 'aa')]" ; expected = $false }
131+ @ { expression = " [less('a', 'b')]" ; expected = $true }
132+ @ { expression = " [less('b', 'a')]" ; expected = $false }
133+ @ { expression = " [less('A', 'a')]" ; expected = $true }
134+ @ { expression = " [lessOrEquals('a', 'b')]" ; expected = $true }
135+ @ { expression = " [lessOrEquals('b', 'a')]" ; expected = $false }
136+ @ { expression = " [lessOrEquals('a', 'a')]" ; expected = $true }
137+ @ { expression = " [lessOrEquals('aa', 'Aa')]" ; expected = $false }
138+ @ { expression = " [coalesce('DSC', 'World')]" ; expected = ' DSC' }
139+ @ { expression = " [coalesce(42, 'fallback')]" ; expected = 42 }
140+ @ { expression = " [coalesce(true, false)]" ; expected = $true }
141+ @ { expression = " [coalesce('first', 'second')]" ; expected = ' first' }
142+ @ { expression = " [coalesce(createArray('a', 'b'), createArray('c', 'd'))]" ; expected = @ (' a' , ' b' ) }
143+ @ { expression = " [coalesce(null(), 'fallback')]" ; expected = ' fallback' }
144+
145+ @ { expression = " [coalesce(null(), createArray(1, 2, 3))]" ; expected = @ (1 , 2 , 3 ) }
146+ @ { expression = " [coalesce(null(), null(), null(), 'finalValue')]" ; expected = ' finalValue' }
147+ @ { expression = " [coalesce(null(), 42, 'not-reached')]" ; expected = 42 }
148+ @ { expression = " [coalesce(null(), true, false)]" ; expected = $true }
149+ ) {
150+ param ($expression , $expected )
151+ $yaml = @"
151152 `$ schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
152153 resources:
153154 - name: echo
154155 type: Microsoft.DSC.Debug/Echo
155156 properties:
156157 output: "$expression "
157- "@
158+ "@
158159 $out = dsc config get - i $yaml 2> $TestDrive / error.log | ConvertFrom-Json
159160 $LASTEXITCODE | Should - Be 0 - Because (Get-Content $TestDrive / error.log - Raw | Out-String )
160161 $out.results [0 ].result.actualState.output | Should - Be $expected - Because ($out | ConvertTo-Json - Depth 10 | Out-String )
0 commit comments