diff --git a/src/code/PSResourceInfo.cs b/src/code/PSResourceInfo.cs index 0e14f6ce9..db88bfa8a 100644 --- a/src/code/PSResourceInfo.cs +++ b/src/code/PSResourceInfo.cs @@ -970,13 +970,18 @@ public static bool TryConvertFromContainerRegistryJson( { metadata["Dependencies"] = ParseContainerRegistryDependencies(requiredModulesElement, out errorMsg).ToArray(); } + if (string.Equals(packageName, "Az", StringComparison.OrdinalIgnoreCase) || packageName.StartsWith("Az.", StringComparison.OrdinalIgnoreCase)) { - if (rootDom.TryGetProperty("PrivateData", out JsonElement privateDataElement) && privateDataElement.TryGetProperty("PSData", out JsonElement psDataElement)) + if (rootDom.TryGetProperty("ModuleList", out JsonElement moduleListDepsElement)) + { + metadata["Dependencies"] = ParseContainerRegistryDependencies(moduleListDepsElement, out errorMsg).ToArray(); + } + else if (rootDom.TryGetProperty("PrivateData", out JsonElement privateDataElement) && privateDataElement.TryGetProperty("PSData", out JsonElement psDataElement)) { - if (psDataElement.TryGetProperty("ModuleList", out JsonElement moduleListDepsElement)) + if (psDataElement.TryGetProperty("ModuleList", out JsonElement privateDataModuleListDepsElement)) { - metadata["Dependencies"] = ParseContainerRegistryDependencies(moduleListDepsElement, out errorMsg).ToArray(); + metadata["Dependencies"] = ParseContainerRegistryDependencies(privateDataModuleListDepsElement, out errorMsg).ToArray(); } } } diff --git a/test/FindPSResourceTests/FindPSResourceContainerRegistryServer.Tests.ps1 b/test/FindPSResourceTests/FindPSResourceContainerRegistryServer.Tests.ps1 index b15833980..b7ffdfb8e 100644 --- a/test/FindPSResourceTests/FindPSResourceContainerRegistryServer.Tests.ps1 +++ b/test/FindPSResourceTests/FindPSResourceContainerRegistryServer.Tests.ps1 @@ -227,22 +227,32 @@ Describe 'Test HTTP Find-PSResource for ACR Server Protocol' -tags 'CI' { $res.Version | Should -Be "1.0.0" $res.Type.ToString() | Should -Be "Script" } + + It "Should find resource with dependency, given Name and Version" { + $res = Find-PSResource -Name "Az.Storage" -Version "8.0.0" -Repository $ACRRepoName + $res.Dependencies.Length | Should -Be 1 + $res.Dependencies[0].Name | Should -Be "Az.Accounts" + } } Describe 'Test Find-PSResource for MAR Repository' -tags 'CI' { BeforeAll { - [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("MARPrefix", "azure-powershell/"); Register-PSResourceRepository -Name "MAR" -Uri "https://mcr.microsoft.com" -ApiVersion "ContainerRegistry" } AfterAll { - [Microsoft.PowerShell.PSResourceGet.UtilClasses.InternalHooks]::SetTestHook("MARPrefix", $null); Unregister-PSResourceRepository -Name "MAR" } It "Should find resource given specific Name, Version null" { $res = Find-PSResource -Name "Az.Accounts" -Repository "MAR" $res.Name | Should -Be "Az.Accounts" - $res.Version | Should -Be "3.0.4" + $res.Version | Should -Be "4.0.0" + } + + It "Should find resource and its dependency given specific Name and Version" { + $res = Find-PSResource -Name "Az.Storage" -Version "8.0.0" -Repository "MAR" + $res.Dependencies.Length | Should -Be 1 + $res.Dependencies[0].Name | Should -Be "Az.Accounts" } }