Improve type and null handling
This commit is contained in:
Родитель
b94e9e9921
Коммит
5b9cb4a13c
|
@ -591,26 +591,34 @@ Describe "Platform Matrix Environment Variables" -Tag "UnitTest", "envvar" {
|
|||
"matrix": {
|
||||
"foo": "bar",
|
||||
"envReference": ["env:TestMatrixEnvReference", "env:TestMatrixEnvReference2", "noref"]
|
||||
}
|
||||
},
|
||||
"include": [
|
||||
{
|
||||
"foo": "bar",
|
||||
"envReference": "env:TestMatrixEnvReference"
|
||||
}
|
||||
]
|
||||
}
|
||||
'@
|
||||
|
||||
[System.Environment]::SetEnvironmentVariable("TestMatrixEnvReference", "")
|
||||
[array]$matrix = GenerateMatrix (GetMatrixConfigFromJson $matrixJson) "sparse"
|
||||
$matrix.Length | Should -Be 3
|
||||
$matrix.Length | Should -Be 4
|
||||
$matrix[0].name | Should -Be "bar"
|
||||
$matrix[0].parameters.envReference | Should -Be ""
|
||||
|
||||
[System.Environment]::SetEnvironmentVariable("TestMatrixEnvReference", "replaced")
|
||||
[System.Environment]::SetEnvironmentVariable("TestMatrixEnvReference2", "replaced2")
|
||||
[array]$replacedMatrix = GenerateMatrix (GetMatrixConfigFromJson $matrixJson) "sparse"
|
||||
$replacedMatrix.Length | Should -Be 3
|
||||
$replacedMatrix.Length | Should -Be 4
|
||||
$replacedMatrix[0].name | Should -Be "bar_replaced"
|
||||
$replacedMatrix[0].parameters.envReference | Should -Be "replaced"
|
||||
$replacedMatrix[1].name | Should -Be "bar_replaced2"
|
||||
$replacedMatrix[1].parameters.envReference | Should -Be "replaced2"
|
||||
$replacedMatrix[2].name | Should -Be "bar_noref"
|
||||
$replacedMatrix[2].parameters.envReference | Should -Be "noref"
|
||||
$replacedMatrix[3].name | Should -Be "bar_replaced"
|
||||
$replacedMatrix[3].parameters.envReference | Should -Be "replaced"
|
||||
}
|
||||
|
||||
It "Should support filter/replace with variable reference syntax" {
|
||||
|
|
|
@ -76,7 +76,7 @@ class MatrixParameter {
|
|||
$displayName = $this.Value.ToString()
|
||||
}
|
||||
|
||||
if ($displayNamesLookup.ContainsKey($displayName)) {
|
||||
if ($displayNamesLookup -and $displayNamesLookup.ContainsKey($displayName)) {
|
||||
$displayName = $displayNamesLookup[$displayName]
|
||||
}
|
||||
|
||||
|
@ -339,6 +339,9 @@ function ProcessReplace {
|
|||
|
||||
foreach ($element in $matrix) {
|
||||
$replacement = [MatrixParameter[]]@()
|
||||
if (!$element -or $element.Count -eq 0) {
|
||||
continue
|
||||
}
|
||||
|
||||
foreach ($perm in $element._permutation) {
|
||||
$replace = $perm
|
||||
|
@ -372,11 +375,14 @@ function ProcessEnvironmentVariableReferences([array]$matrix, $displayNamesLooku
|
|||
|
||||
foreach ($element in $matrix) {
|
||||
$updated = [MatrixParameter[]]@()
|
||||
if (!$element -or $element.Count -eq 0) {
|
||||
continue
|
||||
}
|
||||
|
||||
foreach ($perm in $element._permutation) {
|
||||
# Iterate nested permutations or run once for singular values (int, string, bool)
|
||||
foreach ($flattened in $perm.Flatten()) {
|
||||
if ($flattened.Value?.GetType() -eq "".GetType() -and $flattened.Value.StartsWith("env:")) {
|
||||
if ($flattened.Value -is [string] -and $flattened.Value.StartsWith("env:")) {
|
||||
$envKey = $flattened.Value.Replace("env:", "")
|
||||
$value = [System.Environment]::GetEnvironmentVariable($envKey) ?? ""
|
||||
if (!$value) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче