@@ -34,9 +34,8 @@ InModuleScope 'ALZ' {
34
34
35
35
[Parameter (Mandatory = $true )]
36
36
[string ]$withValue
37
- )
38
-
39
- return [pscustomobject ]@ {
37
+ )
38
+ $config = [pscustomobject ]@ {
40
39
Nested = [pscustomobject ]@ {
41
40
Type = " Computed"
42
41
Description = " A Test Value"
@@ -48,6 +47,8 @@ InModuleScope 'ALZ' {
48
47
})
49
48
}
50
49
}
50
+
51
+ return $config
51
52
}
52
53
53
54
function Format-ExpectedResult {
@@ -481,6 +482,142 @@ InModuleScope 'ALZ' {
481
482
Write-InformationColored $contentStringAfterParsing - ForegroundColor Yellow - InformationAction Continue
482
483
Should - Invoke - CommandName Out-File - ParameterFilter { $FilePath -eq " test2.parameters.json" -and $InputObject -eq $contentStringAfterParsing } - Scope It
483
484
}
485
+
486
+ It ' Computed, Processed array values replace values correctly' {
487
+ $config = [pscustomobject ]@ {
488
+ Nested = [pscustomobject ]@ {
489
+ Type = " Computed"
490
+ Description = " A Test Value"
491
+ Process = ' @($args | Select-Object -Unique)'
492
+ Value = @ (
493
+ " 1" ,
494
+ " 1" ,
495
+ " 3"
496
+ )
497
+ Targets = @ (
498
+ [pscustomobject ]@ {
499
+ Name = " parValue.value"
500
+ Destination = " Parameters"
501
+ })
502
+ }
503
+ }
504
+
505
+ $fileContent = ' {
506
+ "parameters": {
507
+ "parValue": {
508
+ "value": []
509
+ }
510
+ }
511
+ }'
512
+
513
+ $expectedContent = ' {
514
+ "parameters": {
515
+ "parValue": {
516
+ "value": [ "1", "3" ]
517
+ }
518
+ }
519
+ }'
520
+
521
+ Mock - CommandName Get-Content - ParameterFilter { $Path -eq $testFile1Name } - MockWith {
522
+ $fileContent
523
+ }
524
+
525
+ $expectedContent = Format-ExpectedResult - expectedJson $expectedContent
526
+
527
+ Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $config
528
+
529
+ Should - Invoke - CommandName Out-File `
530
+ - ParameterFilter { $FilePath -eq $testFile1Name -and $InputObject -eq $expectedContent } `
531
+ - Scope It
532
+ }
533
+
534
+ It ' Computed, Processed values replace values correctly' {
535
+ $config = [pscustomobject ]@ {
536
+ Nested = [pscustomobject ]@ {
537
+ Type = " Computed"
538
+ Description = " A Test Value"
539
+ Process = ' ($args[0] -eq "eastus") ? "eastus2" : ($args[0] -eq "eastus2") ? "eastus" : $args[0]'
540
+ Value = " eastus"
541
+ Targets = @ (
542
+ [pscustomobject ]@ {
543
+ Name = " parValue.value"
544
+ Destination = " Parameters"
545
+ })
546
+ }
547
+ }
548
+
549
+ $fileContent = ' {
550
+ "parameters": {
551
+ "parValue": {
552
+ "value": "replace_me"
553
+ }
554
+ }
555
+ }'
556
+
557
+ $expectedContent = ' {
558
+ "parameters": {
559
+ "parValue": {
560
+ "value": "eastus2"
561
+ }
562
+ }
563
+ }'
564
+
565
+ Mock - CommandName Get-Content - ParameterFilter { $Path -eq $testFile1Name } - MockWith {
566
+ $fileContent
567
+ }
568
+
569
+ $expectedContent = Format-ExpectedResult - expectedJson $expectedContent
570
+
571
+ Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $config
572
+
573
+ Should - Invoke - CommandName Out-File `
574
+ - ParameterFilter { $FilePath -eq $testFile1Name -and $InputObject -eq $expectedContent } `
575
+ - Scope It
576
+ }
577
+
578
+ It ' Computed, Processed values replace values correctly' {
579
+ $config = [pscustomobject ]@ {
580
+ Nested = [pscustomobject ]@ {
581
+ Type = " Computed"
582
+ Description = " A Test Value"
583
+ Process = ' ($args[0] -eq "goodbye") ? "Hello" : "Goodbye"'
584
+ Value = " goodbye"
585
+ Targets = @ (
586
+ [pscustomobject ]@ {
587
+ Name = " parValue.value"
588
+ Destination = " Parameters"
589
+ })
590
+ }
591
+ }
592
+
593
+ $fileContent = ' {
594
+ "parameters": {
595
+ "parValue": {
596
+ "value": "replace_me"
597
+ }
598
+ }
599
+ }'
600
+
601
+ $expectedContent = ' {
602
+ "parameters": {
603
+ "parValue": {
604
+ "value": "Hello"
605
+ }
606
+ }
607
+ }'
608
+
609
+ Mock - CommandName Get-Content - ParameterFilter { $Path -eq $testFile1Name } - MockWith {
610
+ $fileContent
611
+ }
612
+
613
+ $expectedContent = Format-ExpectedResult - expectedJson $expectedContent
614
+
615
+ Edit-ALZConfigurationFilesInPlace - alzEnvironmentDestination ' .' - configuration $config
616
+
617
+ Should - Invoke - CommandName Out-File `
618
+ - ParameterFilter { $FilePath -eq $testFile1Name -and $InputObject -eq $expectedContent } `
619
+ - Scope It
620
+ }
484
621
}
485
622
}
486
623
}
0 commit comments