Skip to content

Commit

Permalink
Merge pull request #11268 from jagilber/get-azure-resource-cmdlet-cs
Browse files Browse the repository at this point in the history
Resources/GetAzureResourceCmdlet.cs fix #11267 get-azresource to use actual apiVersion of resource with parameter set -ResourceGroupName -Name -ExpandProperties -ResourceType
  • Loading branch information
isra-fel authored Mar 16, 2020
2 parents 0c3118b + 3fb25d1 commit d205f78
Show file tree
Hide file tree
Showing 5 changed files with 42,608 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ private bool ShouldConstructResourceId(out string resourceId)
ResourceGroupName,
ResourceType,
Name);

this.DefaultApiVersion = DetermineApiVersion(resourceId).Result;

return true;
}

Expand Down Expand Up @@ -626,4 +629,4 @@ private bool IsResourceGroupLevelQuery()
this.ResourceType != null;
}
}
}
}
7 changes: 7 additions & 0 deletions src/Resources/Resources.Test/ScenarioTests/ResourceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ public void TestGetResourceWithExpandProperties()
TestRunner.RunTestScript("Test-GetResourceExpandProperties");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestGetResourceByNameAndType()
{
TestRunner.RunTestScript("Test-GetResourceByNameAndType");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestGetResourceByIdAndProperties()
Expand Down
36 changes: 36 additions & 0 deletions src/Resources/Resources.Test/ScenarioTests/ResourceTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,42 @@ function Test-GetResourceExpandProperties
}
}

<#
.SYNOPSIS
Tests getting a resource by id, name, type, and its properties ensuring default resource api version is *not* used.
#>
function Test-GetResourceByNameAndType
{
# Setup
$rgname = Get-ResourceGroupName
$rname = Get-ResourceName
$location = "West US"
$resourceType = "Microsoft.Resources/deployments"
$apiVersionWithType = "2019-10-01"
$templateFile = "sampleTemplate.json"
$templateParameterFile = "sampleTemplateParams.json"

try
{
# Test
New-AzResourceGroup -Name $rgname -Location $location
$deployment = New-AzResourceGroupDeployment -Name $rname -ResourceGroupName $rgname -TemplateFile $templateFile -TemplateParameterFile $templateParameterFile

Assert-AreEqual Succeeded $deployment.ProvisioningState

$specifiedVersion = get-azresource -ResourceGroupName $rgname -Name $rname -ResourceType $resourceType -ExpandProperties -apiversion $apiVersionWithType
Assert-NotNull $specifiedVersion.type

$unspecifiedVersion = get-azresource -ResourceGroupName $rgname -Name $rname -ResourceType $resourceType -ExpandProperties
Assert-NotNull $unspecifiedVersion.type
Assert-AreEqual $specifiedVersion.Type $unspecifiedVersion.Type
}
finally
{
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Tests getting a resource by id and its properties
Expand Down
Loading

0 comments on commit d205f78

Please sign in to comment.