2
2
# Licensed under the MIT License.
3
3
4
4
Describe ' 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 = @"
18
18
`$ schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
19
19
parameters:
20
20
test:
@@ -40,48 +40,48 @@ Describe 'Expressions tests' {
40
40
type: Microsoft.DSC.Debug/Echo
41
41
properties:
42
42
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
+ }
49
49
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 = @"
58
58
`$ schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
59
59
resources:
60
60
- name: echo
61
61
type: Microsoft.DSC.Debug/Echo
62
62
properties:
63
63
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
+ }
69
69
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 @"
75
75
This is a
76
76
'multi-line'
77
77
string.
78
78
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
+ }
82
82
83
- It 'Nested Group resource does not invoke expressions' {
84
- $yaml = @'
83
+ It ' Nested Group resource does not invoke expressions' {
84
+ $yaml = @'
85
85
$schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
86
86
resources:
87
87
- name: Nested Group
@@ -101,60 +101,61 @@ Describe 'Expressions tests' {
101
101
)]
102
102
dependsOn:
103
103
- "[resourceId('Microsoft/OSInfo', 'Deeply nested OSInfo')]"
104
- '@
104
+ '@
105
105
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
+ }
110
110
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 = @"
151
152
`$ schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
152
153
resources:
153
154
- name: echo
154
155
type: Microsoft.DSC.Debug/Echo
155
156
properties:
156
157
output: "$expression "
157
- "@
158
+ "@
158
159
$out = dsc config get - i $yaml 2> $TestDrive / error.log | ConvertFrom-Json
159
160
$LASTEXITCODE | Should - Be 0 - Because (Get-Content $TestDrive / error.log - Raw | Out-String )
160
161
$out.results [0 ].result.actualState.output | Should - Be $expected - Because ($out | ConvertTo-Json - Depth 10 | Out-String )
0 commit comments