Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync eng/common directory with azure-sdk-tools for PR 1514 #20059

Merged
merged 2 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
}