@@ -35,20 +35,20 @@ InModuleScope 'ALZ' {
35
35
[Parameter (Mandatory = $true )]
36
36
[string ]$withValue
37
37
)
38
- $config = [pscustomobject ]@ {
39
- Nested = [pscustomobject ]@ {
40
- Type = " Computed"
41
- Description = " A Test Value"
42
- Value = $withValue
43
- Targets = @ (
44
- [pscustomobject ]@ {
45
- Name = $configTarget
46
- Destination = " Parameters"
47
- })
48
- }
38
+ $config = [pscustomobject ]@ {
39
+ Nested = [pscustomobject ]@ {
40
+ Type = " Computed"
41
+ Description = " A Test Value"
42
+ Value = $withValue
43
+ Targets = @ (
44
+ [pscustomobject ]@ {
45
+ Name = $configTarget
46
+ Destination = " Parameters"
47
+ })
49
48
}
49
+ }
50
50
51
- return $config
51
+ return $config
52
52
}
53
53
54
54
function Format-ExpectedResult {
@@ -69,7 +69,7 @@ InModuleScope 'ALZ' {
69
69
Context ' Edit-ALZConfigurationFilesInPlace should replace the parameters correctly' {
70
70
71
71
It ' Should replace array values correctly (JSON Object) - first' {
72
- $config = Initialize-TestConfiguration - configTarget " parValue.value.[0]" - withValue " value"
72
+ $config = Initialize-TestConfiguration - configTarget " parValue.value.[0]" - withValue " value"
73
73
74
74
$fileContent = ' {
75
75
"parameters": {
@@ -99,15 +99,15 @@ InModuleScope 'ALZ' {
99
99
100
100
$expectedContent = Format-ExpectedResult - expectedJson $expectedContent
101
101
102
- Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $config
102
+ Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $config
103
103
104
104
Should - Invoke - CommandName Out-File `
105
105
- ParameterFilter { $FilePath -eq $testFile1Name -and $InputObject -eq $expectedContent } `
106
106
- Scope It
107
107
}
108
108
109
109
It ' Should replace array an entire array correctly (JSON Object)' {
110
- $config = Initialize-TestConfiguration - configTarget " parValue.value.[1]" - withValue " value"
110
+ $config = Initialize-TestConfiguration - configTarget " parValue.value.[1]" - withValue " value"
111
111
112
112
$fileContent = ' {
113
113
"parameters": {
@@ -137,7 +137,7 @@ InModuleScope 'ALZ' {
137
137
138
138
$expectedContent = Format-ExpectedResult - expectedJson $expectedContent
139
139
140
- Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $config
140
+ Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $config
141
141
142
142
Should - Invoke - CommandName Out-File `
143
143
- ParameterFilter { $FilePath -eq $testFile1Name -and $InputObject -eq $expectedContent } `
@@ -147,7 +147,7 @@ InModuleScope 'ALZ' {
147
147
It ' Should replace array values correctly (JSON Object) - second' {
148
148
149
149
$config = [pscustomobject ]@ {
150
- Nested = [pscustomobject ]@ {
150
+ Nested = [pscustomobject ]@ {
151
151
Type = " Computed"
152
152
Description = " A Test Value"
153
153
Value = @ (
@@ -185,15 +185,15 @@ InModuleScope 'ALZ' {
185
185
186
186
$expectedContent = Format-ExpectedResult - expectedJson $expectedContent
187
187
188
- Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $config
188
+ Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $config
189
189
190
190
Should - Invoke - CommandName Out-File `
191
191
- ParameterFilter { $FilePath -eq $testFile1Name -and $InputObject -eq $expectedContent } `
192
192
- Scope It
193
193
}
194
194
195
195
It ' Should not write to files that havent been changed.' {
196
- $config = Initialize-TestConfiguration - configTarget " DoesnotExist.value" - withValue " value"
196
+ $config = Initialize-TestConfiguration - configTarget " DoesnotExist.value" - withValue " value"
197
197
198
198
$fileContent = ' {
199
199
"parameters": {
@@ -207,15 +207,15 @@ InModuleScope 'ALZ' {
207
207
$fileContent
208
208
}
209
209
210
- Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $config
210
+ Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $config
211
211
212
212
Should - Invoke - CommandName Out-File `
213
213
- Scope It `
214
214
- Times 0 - Exactly
215
215
}
216
216
217
217
It ' Should replace simple values correctly (Bicep Object)' {
218
- $config = Initialize-TestConfiguration - configTarget " parValue.value" - withValue " value"
218
+ $config = Initialize-TestConfiguration - configTarget " parValue.value" - withValue " value"
219
219
220
220
$fileContent = ' {
221
221
"parameters": {
@@ -239,15 +239,15 @@ InModuleScope 'ALZ' {
239
239
240
240
$expectedContent = Format-ExpectedResult - expectedJson $expectedContent
241
241
242
- Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $config
242
+ Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $config
243
243
244
244
Should - Invoke - CommandName Out-File `
245
245
- ParameterFilter { $FilePath -eq $testFile1Name -and $InputObject -eq $expectedContent } `
246
246
- Scope It
247
247
}
248
248
249
249
It " Should replace 'Parameter' destinations to nested array objects correctly" {
250
- $config = Initialize-TestConfiguration - configTarget " parNested.value.[0].parChildValue.value" - withValue " nested"
250
+ $config = Initialize-TestConfiguration - configTarget " parNested.value.[0].parChildValue.value" - withValue " nested"
251
251
252
252
$fileContent = ' {
253
253
"parameters": {
@@ -279,15 +279,15 @@ InModuleScope 'ALZ' {
279
279
280
280
$expectedContent = Format-ExpectedResult - expectedJson $expectedContent
281
281
282
- Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $config
282
+ Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $config
283
283
284
284
Should - Invoke - CommandName Out-File `
285
285
- ParameterFilter { $FilePath -eq $testFile1Name -and $InputObject -eq $expectedContent } `
286
286
- Scope It
287
287
}
288
288
289
289
It ' Should replace nested values correctly (Plain JSON Object)' {
290
- $config = Initialize-TestConfiguration - configTarget " parNested.value.parChildValue" - withValue " nested"
290
+ $config = Initialize-TestConfiguration - configTarget " parNested.value.parChildValue" - withValue " nested"
291
291
292
292
$fileContent = ' {
293
293
"parameters": {
@@ -315,15 +315,15 @@ InModuleScope 'ALZ' {
315
315
316
316
$expectedContent = Format-ExpectedResult - expectedJson $expectedContent
317
317
318
- Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $config
318
+ Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $config
319
319
320
320
Should - Invoke - CommandName Out-File `
321
321
- ParameterFilter { $FilePath -eq $testFile1Name -and $InputObject -eq $expectedContent } `
322
322
- Scope It
323
323
}
324
324
325
325
It ' Should replace nested values correctly (Bicep Object)' {
326
- $config = Initialize-TestConfiguration - configTarget " parNested.value.parChildValue.value" - withValue " nested"
326
+ $config = Initialize-TestConfiguration - configTarget " parNested.value.parChildValue.value" - withValue " nested"
327
327
328
328
$fileContent = ' {
329
329
"parameters": {
@@ -355,7 +355,7 @@ InModuleScope 'ALZ' {
355
355
356
356
$expectedContent = Format-ExpectedResult - expectedJson $expectedContent
357
357
358
- Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $config
358
+ Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $config
359
359
360
360
Should - Invoke - CommandName Out-File `
361
361
- ParameterFilter { $FilePath -eq $testFile1Name -and $InputObject -eq $expectedContent } `
@@ -378,16 +378,6 @@ InModuleScope 'ALZ' {
378
378
Value = " test"
379
379
DefaultValue = " alz"
380
380
}
381
- Suffix = [pscustomobject ]@ {
382
- Description = " The suffix that will be added to all resources created by this deployment."
383
- Targets = @ (
384
- [pscustomobject ]@ {
385
- Name = " parTopLevelManagementGroupSuffix.value"
386
- Destination = " Parameters"
387
- })
388
- Value = " bla"
389
- DefaultValue = " "
390
- }
391
381
Location = [pscustomobject ]@ {
392
382
Description = " Deployment location."
393
383
Targets = @ (
@@ -434,9 +424,6 @@ InModuleScope 'ALZ' {
434
424
}'
435
425
$secondFileContent = ' {
436
426
"parameters": {
437
- "parTopLevelManagementGroupSuffix": {
438
- "value": ""
439
- },
440
427
"parLocation": {
441
428
"value": ""
442
429
}
@@ -460,7 +447,7 @@ InModuleScope 'ALZ' {
460
447
$secondFileContent
461
448
}
462
449
463
- Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $defaultConfig
450
+ Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $defaultConfig
464
451
465
452
Should - Invoke - CommandName Out-File - Scope It - Times 2
466
453
@@ -475,7 +462,6 @@ InModuleScope 'ALZ' {
475
462
Should - Invoke - CommandName Out-File - ParameterFilter { $FilePath -eq " test1.parameters.json" -and $InputObject -eq $contentStringAfterParsing } - Scope It
476
463
477
464
$contentAfterParsing = ConvertFrom-Json - InputObject $secondFileContent - AsHashtable
478
- $contentAfterParsing.parameters.parTopLevelManagementGroupSuffix.value = ' bla'
479
465
$contentAfterParsing.parameters.parLocation.value = ' eastus'
480
466
481
467
$contentStringAfterParsing = ConvertTo-Json - InputObject $contentAfterParsing
@@ -485,11 +471,11 @@ InModuleScope 'ALZ' {
485
471
486
472
It ' Computed, Processed array values replace values correctly' {
487
473
$config = [pscustomobject ]@ {
488
- Nested = [pscustomobject ]@ {
474
+ Nested = [pscustomobject ]@ {
489
475
Type = " Computed"
490
476
Description = " A Test Value"
491
- Process = ' @($args | Select-Object -Unique)'
492
- Value = @ (
477
+ Process = ' @($args | Select-Object -Unique)'
478
+ Value = @ (
493
479
" 1" ,
494
480
" 1" ,
495
481
" 3"
@@ -524,7 +510,7 @@ InModuleScope 'ALZ' {
524
510
525
511
$expectedContent = Format-ExpectedResult - expectedJson $expectedContent
526
512
527
- Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $config
513
+ Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $config
528
514
529
515
Should - Invoke - CommandName Out-File `
530
516
- ParameterFilter { $FilePath -eq $testFile1Name -and $InputObject -eq $expectedContent } `
@@ -533,11 +519,11 @@ InModuleScope 'ALZ' {
533
519
534
520
It ' Computed, Processed array values replace values correctly in a case insensitive deduplication.' {
535
521
$config = [pscustomobject ]@ {
536
- Nested = [pscustomobject ]@ {
522
+ Nested = [pscustomobject ]@ {
537
523
Type = " Computed"
538
524
Description = " A Test Value"
539
- Process = ' @($args | ForEach-Object { $_.ToLower() } | Select-Object -Unique)'
540
- Value = @ (
525
+ Process = ' @($args | ForEach-Object { $_.ToLower() } | Select-Object -Unique)'
526
+ Value = @ (
541
527
" A" ,
542
528
" a" ,
543
529
" A" ,
@@ -573,7 +559,7 @@ InModuleScope 'ALZ' {
573
559
574
560
$expectedContent = Format-ExpectedResult - expectedJson $expectedContent
575
561
576
- Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $config
562
+ Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $config
577
563
578
564
Should - Invoke - CommandName Out-File `
579
565
- ParameterFilter { $FilePath -eq $testFile1Name -and $InputObject -eq $expectedContent } `
@@ -582,11 +568,11 @@ InModuleScope 'ALZ' {
582
568
583
569
It ' Computed, Processed array values replace values correctly and keep array type when only one item remains.' {
584
570
$config = [pscustomobject ]@ {
585
- Nested = [pscustomobject ]@ {
571
+ Nested = [pscustomobject ]@ {
586
572
Type = " Computed"
587
573
Description = " A Test Value"
588
- Process = ' @($args | Select-Object -Unique)'
589
- Value = @ (
574
+ Process = ' @($args | Select-Object -Unique)'
575
+ Value = @ (
590
576
" 1" ,
591
577
" 1" ,
592
578
" 1"
@@ -621,7 +607,7 @@ InModuleScope 'ALZ' {
621
607
622
608
$expectedContent = Format-ExpectedResult - expectedJson $expectedContent
623
609
624
- Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $config
610
+ Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $config
625
611
626
612
Should - Invoke - CommandName Out-File `
627
613
- ParameterFilter { $FilePath -eq $testFile1Name -and $InputObject -eq $expectedContent } `
@@ -630,10 +616,10 @@ InModuleScope 'ALZ' {
630
616
631
617
It ' Computed, Processed values replace values correctly' {
632
618
$config = [pscustomobject ]@ {
633
- Nested = [pscustomobject ]@ {
619
+ Nested = [pscustomobject ]@ {
634
620
Type = " Computed"
635
621
Description = " A Test Value"
636
- Process = ' ($args[0] -eq "eastus") ? "eastus2" : ($args[0] -eq "eastus2") ? "eastus" : $args[0]'
622
+ Process = ' ($args[0] -eq "eastus") ? "eastus2" : ($args[0] -eq "eastus2") ? "eastus" : $args[0]'
637
623
Value = " eastus"
638
624
Targets = @ (
639
625
[pscustomobject ]@ {
@@ -665,7 +651,7 @@ InModuleScope 'ALZ' {
665
651
666
652
$expectedContent = Format-ExpectedResult - expectedJson $expectedContent
667
653
668
- Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $config
654
+ Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $config
669
655
670
656
Should - Invoke - CommandName Out-File `
671
657
- ParameterFilter { $FilePath -eq $testFile1Name -and $InputObject -eq $expectedContent } `
@@ -674,10 +660,10 @@ InModuleScope 'ALZ' {
674
660
675
661
It ' Computed, Processed values replace values correctly' {
676
662
$config = [pscustomobject ]@ {
677
- Nested = [pscustomobject ]@ {
663
+ Nested = [pscustomobject ]@ {
678
664
Type = " Computed"
679
665
Description = " A Test Value"
680
- Process = ' ($args[0] -eq "goodbye") ? "Hello" : "Goodbye"'
666
+ Process = ' ($args[0] -eq "goodbye") ? "Hello" : "Goodbye"'
681
667
Value = " goodbye"
682
668
Targets = @ (
683
669
[pscustomobject ]@ {
@@ -709,7 +695,7 @@ InModuleScope 'ALZ' {
709
695
710
696
$expectedContent = Format-ExpectedResult - expectedJson $expectedContent
711
697
712
- Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $config
698
+ Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $config
713
699
714
700
Should - Invoke - CommandName Out-File `
715
701
- ParameterFilter { $FilePath -eq $testFile1Name -and $InputObject -eq $expectedContent } `
@@ -718,7 +704,7 @@ InModuleScope 'ALZ' {
718
704
719
705
It ' Multiple files with file specific configuration should be changed correctly' {
720
706
$defaultConfig = [pscustomobject ]@ {
721
- Value1 = [pscustomobject ]@ {
707
+ Value1 = [pscustomobject ]@ {
722
708
Description = " The prefix that will be added to all resources created by this deployment."
723
709
Targets = @ (
724
710
[pscustomobject ]@ {
@@ -729,7 +715,7 @@ InModuleScope 'ALZ' {
729
715
Value = " value1"
730
716
DefaultValue = " alz"
731
717
}
732
- Value2 = [pscustomobject ]@ {
718
+ Value2 = [pscustomobject ]@ {
733
719
Description = " The prefix that will be added to all resources created by this deployment."
734
720
Targets = @ (
735
721
[pscustomobject ]@ {
@@ -760,11 +746,11 @@ InModuleScope 'ALZ' {
760
746
Mock - CommandName Get-ChildItem - ParameterFilter { $Path -match ' config$' } - MockWith {
761
747
@ (
762
748
[PSCustomObject ]@ {
763
- Name = ' test1.parameters.json'
749
+ Name = ' test1.parameters.json'
764
750
FullName = ' test1.parameters.json'
765
751
},
766
752
[PSCustomObject ]@ {
767
- Name = ' test2.parameters.json'
753
+ Name = ' test2.parameters.json'
768
754
FullName = ' test2.parameters.json'
769
755
}
770
756
)
@@ -777,7 +763,7 @@ InModuleScope 'ALZ' {
777
763
$secondFileContent
778
764
}
779
765
780
- Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $defaultConfig
766
+ Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $defaultConfig
781
767
782
768
Should - Invoke - CommandName Out-File - Scope It - Times 2
783
769
0 commit comments