-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11071 from dependabot/dev/brettfo/nuget-unit-test…
…-sdk-install make directory crawling unit-testable
- Loading branch information
Showing
10 changed files
with
113 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Walk from each update directory to the root reporting all global.json files. | ||
function Get-DirectoriesForSdkInstall([string] $repoRoot, [string[]]$updateDirectories) { | ||
$repoRoot = Convert-Path $repoRoot | ||
$repoRootParent = Split-Path -Parent $repoRoot | ||
$globalJsonPaths = @() | ||
foreach ($updateDirectory in $updateDirectories) { | ||
$candidateDir = Convert-Path "$repoRoot/$updateDirectory" | ||
if (Test-Path $candidateDir) { | ||
while ($true) { | ||
$globalJsonPath = Join-Path $candidateDir "global.json" | ||
if (Test-Path $globalJsonPath) { | ||
$repoRelativeGlobalJsonPath = [System.IO.Path]::GetRelativePath($repoRoot, $globalJsonPath).Replace("\", "/") | ||
$globalJsonPaths += $repoRelativeGlobalJsonPath | ||
} | ||
|
||
$candidateDir = Split-Path -Parent $candidateDir | ||
if ($null -eq $candidateDir -or ` | ||
$candidateDir -eq $repoRootParent) { | ||
break | ||
} | ||
} | ||
} | ||
} | ||
|
||
return ,$globalJsonPaths | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
nuget/updater/test-data/global-json-discovery-2-values/global.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"comment": "content unimportant for test" | ||
} |
3 changes: 3 additions & 0 deletions
3
nuget/updater/test-data/global-json-discovery-2-values/src/global.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"comment": "content unimportant for test" | ||
} |
1 change: 1 addition & 0 deletions
1
nuget/updater/test-data/global-json-discovery-none/src/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# empty to force directory creation |
1 change: 1 addition & 0 deletions
1
nuget/updater/test-data/global-json-discovery-root-no-file/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# empty to force directory creation |
3 changes: 3 additions & 0 deletions
3
nuget/updater/test-data/global-json-discovery-root-with-file/global.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"comment": "content unimportant for test" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
Set-StrictMode -version 2.0 | ||
$ErrorActionPreference = "Stop" | ||
|
||
. $PSScriptRoot\common.ps1 | ||
|
||
function Assert-ArraysEqual([string[]]$expected, [string[]]$actual) { | ||
$expectedText = $expected -join ", " | ||
$actualText = $actual -join ", " | ||
if ($expected.Length -ne $actual.Length) { | ||
throw "Expected array length $($expected.Length) but was $($actual.Length). Values: [$expectedText] vs [$actualText]" | ||
} | ||
for ($i = 0; $i -lt $expected.Length; $i++) { | ||
if ($expected[$i] -ne $actual[$i]) { | ||
throw "Expected array element at index $i to be '$($expected[$i])' but was '$($actual[$i])'" | ||
} | ||
} | ||
} | ||
|
||
function Test-GlobalJsonDiscovery([string]$testDirectory, [string[]]$directories, [string[]]$expectedPaths) { | ||
Write-Host "Test-GlobalJsonDiscovery in $testDirectory ... " -NoNewline | ||
$testDirectoryFull = "$PSScriptRoot/test-data/$testDirectory" | ||
$actualPaths = Get-DirectoriesForSdkInstall -repoRoot $testDirectoryFull -updateDirectories $directories | ||
Assert-ArraysEqual -expected $expectedPaths -actual $actualPaths | ||
Write-Host "OK" | ||
} | ||
|
||
try { | ||
# verify SDK updater directories | ||
Test-GlobalJsonDiscovery ` | ||
-testDirectory "global-json-discovery-root-no-file" ` | ||
-directories @("/") ` | ||
-expectedPaths @() | ||
|
||
Test-GlobalJsonDiscovery ` | ||
-testDirectory "global-json-discovery-root-with-file" ` | ||
-directories @("/") ` | ||
-expectedPaths @("global.json") | ||
|
||
Test-GlobalJsonDiscovery ` | ||
-testDirectory "global-json-discovery-none" ` | ||
-directories @("src") ` | ||
-expectedPaths @() | ||
|
||
Test-GlobalJsonDiscovery ` | ||
-testDirectory "global-json-discovery-2-values" ` | ||
-directories @("src") ` | ||
-expectedPaths @("src/global.json", "global.json") | ||
} | ||
catch { | ||
Write-Host $_ | ||
Write-Host $_.Exception | ||
Write-Host $_.ScriptStackTrace | ||
exit 1 | ||
} |