Skip to content

Commit 1d825a3

Browse files
authored
Bugfix for ContainerRegistry repository to parse out dependencies from metadata (#1766)
1 parent 3e23ecb commit 1d825a3

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/code/PSResourceInfo.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -970,13 +970,18 @@ public static bool TryConvertFromContainerRegistryJson(
970970
{
971971
metadata["Dependencies"] = ParseContainerRegistryDependencies(requiredModulesElement, out errorMsg).ToArray();
972972
}
973+
973974
if (string.Equals(packageName, "Az", StringComparison.OrdinalIgnoreCase) || packageName.StartsWith("Az.", StringComparison.OrdinalIgnoreCase))
974975
{
975-
if (rootDom.TryGetProperty("PrivateData", out JsonElement privateDataElement) && privateDataElement.TryGetProperty("PSData", out JsonElement psDataElement))
976+
if (rootDom.TryGetProperty("ModuleList", out JsonElement moduleListDepsElement))
977+
{
978+
metadata["Dependencies"] = ParseContainerRegistryDependencies(moduleListDepsElement, out errorMsg).ToArray();
979+
}
980+
else if (rootDom.TryGetProperty("PrivateData", out JsonElement privateDataElement) && privateDataElement.TryGetProperty("PSData", out JsonElement psDataElement))
976981
{
977-
if (psDataElement.TryGetProperty("ModuleList", out JsonElement moduleListDepsElement))
982+
if (psDataElement.TryGetProperty("ModuleList", out JsonElement privateDataModuleListDepsElement))
978983
{
979-
metadata["Dependencies"] = ParseContainerRegistryDependencies(moduleListDepsElement, out errorMsg).ToArray();
984+
metadata["Dependencies"] = ParseContainerRegistryDependencies(privateDataModuleListDepsElement, out errorMsg).ToArray();
980985
}
981986
}
982987
}

test/FindPSResourceTests/FindPSResourceContainerRegistryServer.Tests.ps1

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,22 +227,32 @@ Describe 'Test HTTP Find-PSResource for ACR Server Protocol' -tags 'CI' {
227227
$res.Version | Should -Be "1.0.0"
228228
$res.Type.ToString() | Should -Be "Script"
229229
}
230+
231+
It "Should find resource with dependency, given Name and Version" {
232+
$res = Find-PSResource -Name "Az.Storage" -Version "8.0.0" -Repository $ACRRepoName
233+
$res.Dependencies.Length | Should -Be 1
234+
$res.Dependencies[0].Name | Should -Be "Az.Accounts"
235+
}
230236
}
231237

232238
Describe 'Test Find-PSResource for MAR Repository' -tags 'CI' {
233239
BeforeAll {
234-
[Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("MARPrefix", "azure-powershell/");
235240
Register-PSResourceRepository -Name "MAR" -Uri "https://mcr.microsoft.com" -ApiVersion "ContainerRegistry"
236241
}
237242

238243
AfterAll {
239-
[Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("MARPrefix", $null);
240244
Unregister-PSResourceRepository -Name "MAR"
241245
}
242246

243247
It "Should find resource given specific Name, Version null" {
244248
$res = Find-PSResource -Name "Az.Accounts" -Repository "MAR"
245249
$res.Name | Should -Be "Az.Accounts"
246-
$res.Version | Should -Be "3.0.4"
250+
$res.Version | Should -Be "4.0.0"
251+
}
252+
253+
It "Should find resource and its dependency given specific Name and Version" {
254+
$res = Find-PSResource -Name "Az.Storage" -Version "8.0.0" -Repository "MAR"
255+
$res.Dependencies.Length | Should -Be 1
256+
$res.Dependencies[0].Name | Should -Be "Az.Accounts"
247257
}
248258
}

0 commit comments

Comments
 (0)