@@ -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,100 @@ 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+ }
585586
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+ "include": [
596+ {
597+ "foo": "bar",
598+ "envReference": "env:TestMatrixEnvReference"
599+ }
600+ ]
601+ }
602+ '@
603+
604+ [System.Environment ]::SetEnvironmentVariable(" TestMatrixEnvReference" , " " )
605+ { GenerateMatrix (GetMatrixConfigFromJson $matrixJson ) " sparse" } | Should - Throw
606+
607+ [System.Environment ]::SetEnvironmentVariable(" TestMatrixEnvReference" , " replaced" )
608+ [System.Environment ]::SetEnvironmentVariable(" TestMatrixEnvReference2" , " replaced2" )
609+ [array ]$replacedMatrix = GenerateMatrix (GetMatrixConfigFromJson $matrixJson ) " sparse"
610+ $replacedMatrix.Length | Should - Be 4
611+ $replacedMatrix [0 ].name | Should - Be " bar_replaced"
612+ $replacedMatrix [0 ].parameters.envReference | Should - Be " replaced"
613+ $replacedMatrix [1 ].name | Should - Be " bar_replaced2"
614+ $replacedMatrix [1 ].parameters.envReference | Should - Be " replaced2"
615+ $replacedMatrix [2 ].name | Should - Be " bar_noref"
616+ $replacedMatrix [2 ].parameters.envReference | Should - Be " noref"
617+ $replacedMatrix [3 ].name | Should - Be " bar_replaced"
618+ $replacedMatrix [3 ].parameters.envReference | Should - Be " replaced"
619+ }
620+
621+ It " Should support filter/replace with variable reference syntax" {
622+ $matrixJson = @'
623+ {
624+ "displayNames": {
625+ "env:replaceme": "env:TestMatrixEnvReference"
626+ },
627+ "matrix": {
628+ "foo": "bar",
629+ "envReference": "env:replaceme"
630+ }
631+ }
632+ '@
633+
634+ [System.Environment ]::SetEnvironmentVariable(" TestMatrixEnvReference" , " replaced" )
635+
636+ [array ]$replacedMatrix = GenerateMatrix `
637+ - config (GetMatrixConfigFromJson $matrixJson ) `
638+ - selectFromMatrixType " sparse" `
639+ -replace @ (" envReference=env:replaceme/env:TestMatrixEnvReference" )
640+ $replacedMatrix.Length | Should - Be 1
641+ $replacedMatrix [0 ].name | Should - Be " bar_replaced"
642+ $replacedMatrix [0 ].parameters.envReference | Should - Be " replaced"
643+
644+ # Don't filter out by replaced values, but by original references
645+ [System.Environment ]::SetEnvironmentVariable(" replaceme" , " filter_replaced" )
646+ [array ]$replacedMatrix = GenerateMatrix `
647+ - config (GetMatrixConfigFromJson $matrixJson ) `
648+ - selectFromMatrixType " sparse" `
649+ - filter @ (" envReference=env:replaceme" )
650+ $replacedMatrix.Length | Should - Be 1
651+ $replacedMatrix [0 ].name | Should - Be " bar_filter_replaced"
652+ $replacedMatrix [0 ].parameters.envReference | Should - Be " filter_replaced"
653+ }
654+
655+ It " Should support display name and display name filter with variable reference syntax" {
656+ $matrixJson = @'
657+ {
658+ "displayNames": {
659+ "replaced": "display"
660+ },
661+ "matrix": {
662+ "foo": "bar",
663+ "envReference": "env:TestMatrixEnvReference"
664+ }
665+ }
666+ '@
667+
668+ [System.Environment ]::SetEnvironmentVariable(" TestMatrixEnvReference" , " replaced" )
669+ [array ]$replacedMatrix = GenerateMatrix (GetMatrixConfigFromJson $matrixJson ) " sparse"
670+ $replacedMatrix.Length | Should - Be 1
671+ $replacedMatrix [0 ].name | Should - Be " bar_display"
672+ $replacedMatrix [0 ].parameters.envReference | Should - Be " replaced"
673+
674+ [System.Environment ]::SetEnvironmentVariable(" TestMatrixEnvReference" , " replaced" )
675+ [array ]$replacedMatrix = GenerateMatrix `
676+ - config (GetMatrixConfigFromJson $matrixJson ) `
677+ - selectFromMatrixType " sparse" `
678+ - displayNameFilter " doesnotexist"
679+ $replacedMatrix | Should - BeNullOrEmpty
680+ }
586681}
0 commit comments