Sync eng/common directory with azure-sdk-tools for PR 1514 (#1960)

* 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>
This commit is contained in:
Azure SDK Bot 2021-03-23 12:51:00 -07:00 committed by GitHub
parent 3d1a58e3f8
commit b6c354f435
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 94 additions and 19 deletions

View File

@ -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)) {
@ -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, @()
}

View File

@ -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 = @'
{

View File

@ -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
@ -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"
}
}