@@ -2,7 +2,7 @@ Import-Module Pester
22
33
44BeforeAll {
5- . $PSScriptRoot / ../ ../ ../ common/ scripts/ job- matrix/ job- matrix- functions.ps1
5+ . $PSScriptRoot / ../ ../ ../ common/ scripts/ job- matrix/ job- matrix- functions.ps1
66
77 function CompareMatrices ([Array ]$matrix , [Array ]$expected ) {
88 $matrix.Length | Should - Be $expected.Length
@@ -33,25 +33,25 @@ Describe "Platform Matrix nonSparse" -Tag "UnitTest", "nonsparse" {
3333 }
3434
3535 It " Should process nonSparse parameters" {
36- $parameters , $nonSparse = ProcessNonSparseParameters $config.matrixParameters " testField1" , " testField3"
36+ $parameters , $nonSparse = ProcessNonSparseParameters $config.matrixParameters " testField1" , " testField3"
3737
3838 $parameters.Count | Should - Be 1
3939 $parameters [0 ].Name | Should - Be " testField2"
40- $parameters [0 ].Value | Should - Be 1 , 2 , 3
40+ $parameters [0 ].Value | Should - Be 1 , 2 , 3
4141
4242 $nonSparse.Count | Should - Be 2
4343 $nonSparse [0 ].Name | Should - Be " testField1"
44- $nonSparse [0 ].Value | Should - Be 1 , 2
44+ $nonSparse [0 ].Value | Should - Be 1 , 2
4545 $nonSparse [1 ].Name | Should - Be " testField3"
46- $nonSparse [1 ].Value | Should - Be 1 , 2 , 3 , 4
46+ $nonSparse [1 ].Value | Should - Be 1 , 2 , 3 , 4
4747
4848 $parameters , $nonSparse = ProcessNonSparseParameters $config.matrixParameters " testField3"
4949 $parameters.Count | Should - Be 2
5050 ($parameters ).Name -match " testField3" | Should - Be $null
5151
5252 $nonSparse.Count | Should - Be 1
5353 $nonSparse [0 ].Name | Should - Be " testField3"
54- $nonSparse [0 ].Value | Should - Be 1 , 2 , 3 , 4
54+ $nonSparse [0 ].Value | Should - Be 1 , 2 , 3 , 4
5555 }
5656
5757 It " Should ignore nonSparse with all selection" {
@@ -77,10 +77,10 @@ Describe "Platform Matrix nonSparse" -Tag "UnitTest", "nonsparse" {
7777'@
7878 $config = GetMatrixConfigFromJson $matrixJson
7979
80- $matrix = GenerateMatrix $config " all" - nonSparseParameters " testField3" , " testField4"
80+ $matrix = GenerateMatrix $config " all" - nonSparseParameters " testField3" , " testField4"
8181 $matrix.Length | Should - Be 16
8282
83- $matrix = GenerateMatrix $config " sparse" - nonSparseParameters " testField3" , " testField4"
83+ $matrix = GenerateMatrix $config " sparse" - nonSparseParameters " testField3" , " testField4"
8484 $matrix.Length | Should - Be 8
8585 }
8686
@@ -125,13 +125,13 @@ Describe "Platform Matrix nonSparse" -Tag "UnitTest", "nonsparse" {
125125 }
126126}
127127
128- # This test is currently disabled (it doesn't have "UnitTest" tag) as it fails
128+ # This test is currently disabled (it doesn't have "UnitTest" tag) as it fails
129129# in test "Should generate a sparse matrix where the entire base matrix is imported" on line:
130130#
131131# $matrix = GenerateMatrix $importConfig "sparse"
132132#
133133# with message:
134- #
134+ #
135135# ParameterBindingArgumentTransformationException: Cannot process argument transformation on parameter 'parameters'. Cannot convert the "System.Collections.Hashtable" value of type "System.Collections.Hashtable" to type "MatrixParameter".
136136#
137137# See full build failure:
@@ -392,11 +392,11 @@ Describe "Platform Matrix Import" -Tag "import" {
392392
393393Describe " Platform Matrix Replace" - Tag " UnitTest" , " replace" {
394394 It " Should parse replacement syntax" - TestCases @ (
395- @ { query = ' foo=bar/baz' ; key = ' ^foo$' ; value = ' ^bar$' ; replace = ' baz' },
396- @ { query = ' foo=\/p:bar/\/p:baz' ; key = ' ^foo$' ; value = ' ^\/p:bar$' ; replace = ' /p:baz' },
397- @ { query = ' f\=o\/o=\/p:b\=ar/\/p:b\=az' ; key = ' ^f\=o\/o$' ; value = ' ^\/p:b\=ar$' ; replace = ' /p:b=az' },
398- @ { query = ' foo=bar/' ; key = ' ^foo$' ; value = ' ^bar$' ; replace = ' ' },
399- @ { query = ' foo=/baz' ; key = ' ^foo$' ; value = ' ^$' ; replace = ' baz' }
395+ @ { query = ' foo=bar/baz' ; key = ' ^foo$' ; value = ' ^bar$' ; replace = ' baz' },
396+ @ { query = ' foo=\/p:bar/\/p:baz' ; key = ' ^foo$' ; value = ' ^\/p:bar$' ; replace = ' /p:baz' },
397+ @ { query = ' f\=o\/o=\/p:b\=ar/\/p:b\=az' ; key = ' ^f\=o\/o$' ; value = ' ^\/p:b\=ar$' ; replace = ' /p:b=az' },
398+ @ { query = ' foo=bar/' ; key = ' ^foo$' ; value = ' ^bar$' ; replace = ' ' },
399+ @ { query = ' foo=/baz' ; key = ' ^foo$' ; value = ' ^$' ; replace = ' baz' }
400400 ) {
401401 $parsed = ParseReplacement $query
402402 $parsed.key | Should - Be $key
@@ -582,5 +582,95 @@ Describe "Platform Matrix Replace" -Tag "UnitTest", "replace" {
582582 $matrix [2 ].parameters.Baz | Should - Be " importedBaz"
583583 $matrix [2 ].parameters.replaceme | Should - Be " replaceme"
584584 }
585+ }
586+
587+ Describe " Platform Matrix Environment Variables" - Tag " UnitTest" , " envvar" {
588+ It " Should parse environment variable reference syntax" {
589+ $matrixJson = @'
590+ {
591+ "matrix": {
592+ "foo": "bar",
593+ "envReference": ["env:TestMatrixEnvReference", "env:TestMatrixEnvReference2", "noref"]
594+ }
595+ }
596+ '@
597+
598+ [System.Environment ]::SetEnvironmentVariable(" TestMatrixEnvReference" , " " )
599+ [array ]$matrix = GenerateMatrix (GetMatrixConfigFromJson $matrixJson ) " sparse"
600+ $matrix.Length | Should - Be 3
601+ $matrix [0 ].name | Should - Be " bar"
602+ $matrix [0 ].parameters.envReference | Should - Be " "
603+
604+ [System.Environment ]::SetEnvironmentVariable(" TestMatrixEnvReference" , " replaced" )
605+ [System.Environment ]::SetEnvironmentVariable(" TestMatrixEnvReference2" , " replaced2" )
606+ [array ]$replacedMatrix = GenerateMatrix (GetMatrixConfigFromJson $matrixJson ) " sparse"
607+ $replacedMatrix.Length | Should - Be 3
608+ $replacedMatrix [0 ].name | Should - Be " bar_replaced"
609+ $replacedMatrix [0 ].parameters.envReference | Should - Be " replaced"
610+ $replacedMatrix [1 ].name | Should - Be " bar_replaced2"
611+ $replacedMatrix [1 ].parameters.envReference | Should - Be " replaced2"
612+ $replacedMatrix [2 ].name | Should - Be " bar_noref"
613+ $replacedMatrix [2 ].parameters.envReference | Should - Be " noref"
614+ }
615+
616+ It " Should support filter/replace with variable reference syntax" {
617+ $matrixJson = @'
618+ {
619+ "displayNames": {
620+ "env:replaceme": "env:TestMatrixEnvReference"
621+ },
622+ "matrix": {
623+ "foo": "bar",
624+ "envReference": "env:replaceme"
625+ }
626+ }
627+ '@
628+
629+ [System.Environment ]::SetEnvironmentVariable(" TestMatrixEnvReference" , " replaced" )
630+
631+ [array ]$replacedMatrix = GenerateMatrix `
632+ - config (GetMatrixConfigFromJson $matrixJson ) `
633+ - selectFromMatrixType " sparse" `
634+ -replace @ (" envReference=env:replaceme/env:TestMatrixEnvReference" )
635+ $replacedMatrix.Length | Should - Be 1
636+ $replacedMatrix [0 ].name | Should - Be " bar_replaced"
637+ $replacedMatrix [0 ].parameters.envReference | Should - Be " replaced"
638+
639+ # Don't filter out by replaced values, but by original references
640+ [System.Environment ]::SetEnvironmentVariable(" replaceme" , " filter_replaced" )
641+ [array ]$replacedMatrix = GenerateMatrix `
642+ - config (GetMatrixConfigFromJson $matrixJson ) `
643+ - selectFromMatrixType " sparse" `
644+ - filter @ (" envReference=env:replaceme" )
645+ $replacedMatrix.Length | Should - Be 1
646+ $replacedMatrix [0 ].name | Should - Be " bar_filter_replaced"
647+ $replacedMatrix [0 ].parameters.envReference | Should - Be " filter_replaced"
648+ }
585649
650+ It " Should support display name and display name filter with variable reference syntax" {
651+ $matrixJson = @'
652+ {
653+ "displayNames": {
654+ "replaced": "display"
655+ },
656+ "matrix": {
657+ "foo": "bar",
658+ "envReference": "env:TestMatrixEnvReference"
659+ }
586660}
661+ '@
662+
663+ [System.Environment ]::SetEnvironmentVariable(" TestMatrixEnvReference" , " replaced" )
664+ [array ]$replacedMatrix = GenerateMatrix (GetMatrixConfigFromJson $matrixJson ) " sparse"
665+ $replacedMatrix.Length | Should - Be 1
666+ $replacedMatrix [0 ].name | Should - Be " bar_display"
667+ $replacedMatrix [0 ].parameters.envReference | Should - Be " replaced"
668+
669+ [System.Environment ]::SetEnvironmentVariable(" TestMatrixEnvReference" , " replaced" )
670+ [array ]$replacedMatrix = GenerateMatrix `
671+ - config (GetMatrixConfigFromJson $matrixJson ) `
672+ - selectFromMatrixType " sparse" `
673+ - displayNameFilter " doesnotexist"
674+ $replacedMatrix | Should - BeNullOrEmpty
675+ }
676+ }
0 commit comments