Skip to content

Commit

Permalink
Sync eng/common directory with azure-sdk-tools for PR 1514 (#14448)
Browse files Browse the repository at this point in the history
* Handle null values when generating display names

* Fix issue processing matrices where the base matrix is only an import

Co-authored-by: Ben Broderick Phillips <bebroder@microsoft.com>
  • Loading branch information
azure-sdk and benbp authored Mar 23, 2021
1 parent ef26e93 commit 0b2b097
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 19 deletions.
9 changes: 6 additions & 3 deletions eng/common/scripts/job-matrix/job-matrix-functions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,12 @@ class MatrixParameter {

[String]CreateDisplayName([Hashtable]$displayNamesLookup)
{
$displayName = $this.Value.ToString()
if ($this.Value -is [PSCustomObject]) {
if ($null -eq $this.Value) {
$displayName = ""
} elseif ($this.Value -is [PSCustomObject]) {
$displayName = $this.Name
} else {
$displayName = $this.Value.ToString()
}

if ($displayNamesLookup.ContainsKey($displayName)) {
Expand Down Expand Up @@ -347,7 +350,7 @@ function ProcessImport([MatrixParameter[]]$matrix, [String]$selection, [Hashtabl
$importPath = $_.Value
}
}
if (!$matrix -or !$importPath) {
if ((!$matrix -and !$importPath) -or !$importPath) {
return $matrix, @()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,49 @@ Describe "Platform Matrix nonSparse" -Tag "nonsparse" {
}

Describe "Platform Matrix Import" -Tag "import" {
It "Should generate a sparse matrix where the entire base matrix is imported" {
$matrixJson = @'
{
"matrix": {
"$IMPORT": "./test-import-matrix.json"
},
"include": [
{
"fooinclude": "fooinclude"
}
]
}
'@

$expectedMatrix = @'
[
{
"parameters": { "Foo": "foo1", "Bar": "bar1" },
"name": "foo1_bar1"
},
{
"parameters": { "Foo": "foo2", "Bar": "bar2" },
"name": "foo2_bar2"
},
{
"parameters": { "Baz": "importedBaz" },
"name": "importedBazName"
},
{
"parameters": { "fooinclude": "fooinclude" },
"name": "fooinclude"
},
]
'@

$importConfig = GetMatrixConfigFromJson $matrixJson
$matrix = GenerateMatrix $importConfig "sparse"
$expected = $expectedMatrix | ConvertFrom-Json -AsHashtable

$matrix.Length | Should -Be 4
CompareMatrices $matrix $expected
}

It "Should generate a matrix with nonSparseParameters and an imported sparse matrix" {
$matrixJson = @'
{
Expand Down
61 changes: 45 additions & 16 deletions eng/common/scripts/job-matrix/tests/job-matrix-functions.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -324,22 +324,6 @@ Describe "Platform Matrix Generation" -Tag "generate" {
$element.name | Should -Be "macOS1015_netcoreapp21_withFoo"
}

It "Should enforce valid display name format" {
$generateconfig.displayNamesLookup["net461"] = '123.Some.456.Invalid_format-name$(foo)'
$generateconfig.displayNamesLookup["netcoreapp2.1"] = (New-Object string[] 150) -join "a"
$dimensions = GetMatrixDimensions $generateConfig.matrixParameters
$matrix = GenerateFullMatrix $generateconfig.matrixParameters $generateconfig.displayNamesLookup

$element = GetNdMatrixElement @(0, 0, 0) $matrix $dimensions
$element.name | Should -Be "windows2019_123some456invalid_formatnamefoo"

$element = GetNdMatrixElement @(1, 1, 1) $matrix $dimensions
$element.name.Length | Should -Be 100
# The withfoo part of the argument gets cut off at the character limit
$element.name | Should -BeLike "ubuntu1804_aaaaaaaaaaaaaaaaa*"
}


It "Should initialize an N-dimensional matrix from all parameter permutations" {
$dimensions = GetMatrixDimensions $generateConfig.matrixParameters
$matrix = GenerateFullMatrix $generateConfig.matrixParameters $generateConfig.displayNamesLookup
Expand Down Expand Up @@ -587,3 +571,48 @@ Describe "Platform Matrix Generation With Object Fields" -Tag "objectfields" {
$matrix[4].parameters.Count | Should -Be 3
}
}

Describe "Platform Matrix Display Names" -Tag "displaynames" {
BeforeEach {
$matrixConfigForGenerate = @"
{
"displayNames": {
"--enableFoo": "withfoo"
},
"matrix": {
"operatingSystem": "ubuntu-18.04",
"framework": [
"net461",
"netcoreapp2.1"
],
"TestNullField": null,
"TestObjectField": {
"TestObjectValueName": {
"foo": "bar",
"baz": "qux"
}
}
}
}
"@
$generateConfig = GetMatrixConfigFromJson $matrixConfigForGenerate
}

It "Should enforce valid display name format" {
$generateconfig.displayNamesLookup["net461"] = '123.Some.456.Invalid_format-name$(foo)'
$generateconfig.displayNamesLookup["netcoreapp2.1"] = (New-Object string[] 150) -join "a"
$dimensions = GetMatrixDimensions $generateConfig.matrixParameters
$matrix = GenerateFullMatrix $generateconfig.matrixParameters $generateconfig.displayNamesLookup

$matrix[0].name | Should -Be "ubuntu1804_123some456invalid_formatnamefoo_TestObjectValueName"

$matrix[1].name.Length | Should -Be 100
# The withfoo part of the argument gets cut off at the character limit
$matrix[1].name | Should -BeLike "ubuntu1804_aaaaaaaaaaaaaaaaa*"
}

It "Should generate a display name with null and object values" {
$matrix = GenerateMatrix $generateConfig "sparse"
$matrix[0].name | Should -Be "ubuntu1804_net461_TestObjectValueName"
}
}

0 comments on commit 0b2b097

Please sign in to comment.