Skip to content

Commit 1d361a1

Browse files
Reference newly generated Track 1 SDK in Tags Resources cmdlets (#22348)
* Initial commit to use Track 1 SDK for Tags and support a 202 response code for Tags PUT/PATCH/DELETE * Remove commented code from test case * Fix tests to check for async behavior * Add Purview project to tests * Update test cases * Mark Tags tests using Az.Purview as LiveOnly * Mark Tags tests using Az.Purview as LiveOnly pt 2
1 parent f0b3189 commit 1d361a1

19 files changed

+4338
-884
lines changed

src/Resources/ResourceManager/Implementation/Policy/PsPolicyIdentity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public PsPolicyIdentity(JToken input)
1818
PrincipalId = identity.PrincipalId;
1919
TenantId = identity.TenantId;
2020

21-
var userAssignedIdentityId = identity.UserAssignedIdentities?.Take(1).Select(d => d.Key).First();
21+
var userAssignedIdentityId = identity.UserAssignedIdentities?.Take(1).Select(d => d.Key).FirstOrDefault();
2222

2323
UserAssignedIdentities = userAssignedIdentityId != null ?
2424
new Dictionary<string, PsUserAssignedIdentity>

src/Resources/Resources.Test/Resources.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
<ProjectReference Include="..\Resources\Resources.csproj" />
2525
<ProjectReference Include="..\..\ManagedServiceIdentity\Az.ManagedServiceIdentity.csproj" />
2626
<ProjectReference Include="..\Resources.Sdk\Resources.Sdk.csproj" />
27+
<ProjectReference Include="..\..\Purview\Purview\Purview.csproj" />
28+
<ProjectReference Include="..\..\Purview\Purview.Autorest\Az.Purview.csproj" />
29+
<ProjectReference Include="..\..\Purview\Purviewdata.Autorest\Az.Purviewdata.csproj" />
2730
</ItemGroup>
2831

2932
<ItemGroup>

src/Resources/Resources.Test/ScenarioTests/ResourcesTestRunner.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ protected ResourcesTestRunner(ITestOutputHelper output)
4343
{
4444
helper.RMResourceModule,
4545
helper.GetRMModulePath("Az.Monitor.psd1"),
46-
helper.GetRMModulePath("Az.ManagedServiceIdentity.psd1")
46+
helper.GetRMModulePath("Az.ManagedServiceIdentity.psd1"),
47+
helper.GetRMModulePath("Az.Purview.psd1")
4748
})
4849
.WithRecordMatcher(
4950
(ignoreResourcesClient, resourceProviders, userAgentsToIgnore) => new ResourcesRecordMatcher(ignoreResourcesClient, resourceProviders, userAgentsToIgnore)

src/Resources/Resources.Test/ScenarioTests/TagTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,26 @@ public void TagDeleteWithResourceIdParamsForResource()
7979
{
8080
TestRunner.RunTestScript("Test-TagDeleteWithResourceIdParamsForResource");
8181
}
82+
83+
[Fact]
84+
[Trait(Category.RunType, Category.LiveOnly)]
85+
public void TagCreateOrUpdateAsyncWithResourceIdParamsForResource()
86+
{
87+
TestRunner.RunTestScript("Test-TagCreateOrUpdateAsyncWithResourceIdParamsForResource");
88+
}
89+
90+
[Fact]
91+
[Trait(Category.RunType, Category.LiveOnly)]
92+
public void TagUpdateAsyncWithResourceIdParamsForResource()
93+
{
94+
TestRunner.RunTestScript("Test-TagUpdateAsyncWithResourceIdParamsForResource");
95+
}
96+
97+
[Fact]
98+
[Trait(Category.RunType, Category.LiveOnly)]
99+
public void TagDeleteAsyncWithResourceIdParamsForResource()
100+
{
101+
TestRunner.RunTestScript("Test-TagDeleteAsyncWithResourceIdParamsForResource");
102+
}
82103
}
83104
}

src/Resources/Resources.Test/ScenarioTests/TagTests.ps1

Lines changed: 178 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,44 @@ function Test-TagCreateOrUpdateWithResourceIdParamsForResource
6161
Test-TagCreateOrUpdateWithResourceIdParams $resourceId
6262
}
6363

64+
<#
65+
.SYNOPSIS
66+
Utility method to test async CreateOrUpdate for Tags within tracked resources and subscription.
67+
#>
68+
function Test-TagCreateOrUpdateAsyncWithResourceIdParams($resourceId)
69+
{
70+
# Setup
71+
$expected = @{"key1"="value1"; "key2"="value2";}
72+
73+
try
74+
{
75+
# Test
76+
$newTagres = New-AzTag -ResourceId $resourceId -Tag $expected
77+
Start-TestSleep -Seconds 120
78+
$res = Get-AzTag -ResourceId $resourceId
79+
80+
[hashtable]$actual = $res.Properties.TagsProperty
81+
Assert-True { AreHashtableEqual $expected $actual }
82+
}
83+
finally
84+
{
85+
# Cleanup
86+
Remove-AzTag -ResourceId $resourceId
87+
}
88+
}
89+
90+
<#
91+
.SYNOPSIS
92+
Tests creating or updating tags on tracked resource.
93+
#>
94+
function Test-TagCreateOrUpdateAsyncWithResourceIdParamsForResource
95+
{
96+
# Setup
97+
$resourceId = NewTestResourcePurviewAccount
98+
99+
Test-TagCreateOrUpdateAsyncWithResourceIdParams $resourceId
100+
}
101+
64102

65103
<#
66104
.SYNOPSIS
@@ -143,6 +181,77 @@ function Test-TagUpdateWithResourceIdParamsForResource
143181
Test-UpdateWithResourceIdParams $resourceId
144182
}
145183

184+
<#
185+
.SYNOPSIS
186+
Utility method to test async updating tags on subscription and tracked resource, including Merge, Replace, and Delete Operation.
187+
#>
188+
function Test-UpdateAsyncWithResourceIdParams($resourceId)
189+
{
190+
# Setup
191+
$original = @{"key1"="value1"; "key2"="value2";}
192+
New-AzTag -ResourceId $resourceId -Tag $original
193+
Start-TestSleep -Seconds 120
194+
195+
try
196+
{
197+
# Test
198+
{
199+
# merge operation
200+
$merged = @{"key1"="value1"; "key3"="value3";}
201+
$res = Update-AzTag -ResourceId $resourceId -Tag $merged -Operation Merge
202+
Start-TestSleep -Seconds 120
203+
204+
$expected = @{"key1"="value1"; "key2"="value2"; "key3"="value3";}
205+
[hashtable]$actual = $res.Properties.TagsProperty
206+
207+
# Assert
208+
Assert-True { AreHashtableEqual $expected $actual }
209+
}
210+
211+
{
212+
# replace operation
213+
$replaced = @{"key1"="value1"; "key3"="value3";}
214+
$res = Update-AzTag -ResourceId $resourceId -Tag $replaced -Operation Replace
215+
Start-TestSleep -Seconds 120
216+
217+
$expected = $replaced
218+
[hashtable]$actual = $res.Properties.TagsProperty
219+
220+
# Assert
221+
Assert-True { AreHashtableEqual $expected $actual }
222+
}
223+
224+
{
225+
# delete operation
226+
$deleted = @{"key1"="value1"; "key3"="value3";}
227+
$res = Update-AzTag -ResourceId $resourceId -Tag $deleted -Operation Delete
228+
Start-TestSleep -Seconds 120
229+
230+
$expected = null
231+
[hashtable]$actual = $res.Properties.TagsProperty
232+
233+
# Assert
234+
Assert-True { AreHashtableEqual $expected $actual }
235+
}
236+
}
237+
finally
238+
{
239+
# Cleanup
240+
Remove-AzTag -ResourceId $resourceId
241+
}
242+
}
243+
244+
<#
245+
.SYNOPSIS
246+
Tests async updating tags on tracked resource.
247+
#>
248+
function Test-TagUpdateAsyncWithResourceIdParamsForResource
249+
{
250+
# Setup
251+
$resourceId = NewTestResourcePurviewAccount
252+
253+
Test-UpdateAsyncWithResourceIdParams $resourceId
254+
}
146255

147256
<#
148257
.SYNOPSIS
@@ -247,6 +356,46 @@ function Test-TagDeleteWithResourceIdParamsForResource
247356
Test-TagDeleteWithResourceIdParams $resourceId
248357
}
249358

359+
<#
360+
.SYNOPSIS
361+
Utility method to test Delete for Tags within tracked resources and subscription.
362+
#>
363+
function Test-TagDeleteAsyncWithResourceIdParams($resourceId)
364+
{
365+
# Setup
366+
$original = @{"key1"="value1"; "key2"="value2";}
367+
New-AzTag -ResourceId $resourceId -Tag $original
368+
Start-TestSleep -Seconds 120
369+
370+
try
371+
{
372+
# Test
373+
Remove-AzTag -ResourceId $resourceId
374+
Start-TestSleep -Seconds 120
375+
$actual = Get-AzTag -ResourceId $resourceId
376+
377+
# Assert
378+
Assert-AreEqual $actual.Properties.TagsProperty.Count 0
379+
}
380+
finally
381+
{
382+
# Cleanup
383+
Remove-AzTag -ResourceId $resourceId
384+
}
385+
}
386+
387+
<#
388+
.SYNOPSIS
389+
Tests getting tags on tracked resource.
390+
#>
391+
function Test-TagDeleteAsyncWithResourceIdParamsForResource
392+
{
393+
# Setup
394+
$resourceId = NewTestResourcePurviewAccount
395+
396+
Test-TagDeleteAsyncWithResourceIdParams $resourceId
397+
}
398+
250399
<#
251400
.SYNOPSIS
252401
utility method to get default subscriptionId
@@ -265,13 +414,13 @@ utility method to create resource group
265414
#>
266415
function NewTestResourceGroup
267416
{
268-
$rgName = "RG-Test05"
417+
$rgName = Get-ResourceGroupName
269418
$location = "Central US"
270419

271-
$existed = Get-AzureRmResourceGroup -Name $rgName -ErrorVariable notPresent -ErrorAction SilentlyContinue
420+
$existed = Get-AzResourceGroup -Name $rgName -ErrorVariable notPresent -ErrorAction SilentlyContinue
272421

273422
if($notPresent) {
274-
$existed = New-AzureRmResourceGroup -Name $rgName -Location $location
423+
$existed = New-AzResourceGroup -Name $rgName -Location $location
275424
}
276425

277426
return $existed
@@ -285,18 +434,40 @@ function NewTestResource
285434
{
286435
$rg = NewTestResourceGroup
287436

288-
$resourceName = "RS-Test05"
437+
$resourceName = Get-ResourceName
289438
$resourceId = $rg.ResourceId + "/providers/microsoft.web/sites/" + $resourceName
290439

291-
$location = "Central US"
440+
$location = "West Central US"
292441
$property = @{test="test-tag"}
293442
$resourceType = "microsoft.web/sites"
294443

295-
$existed = Get-AzureRmResource -ResourceId $resourceId -ErrorVariable notPresent -ErrorAction SilentlyContinue
444+
$existed = Get-AzResource -ResourceId $resourceId -ErrorVariable notPresent -ErrorAction SilentlyContinue
296445

297446
if($notPresent) {
298-
$existed = New-AzureRmResource -Location $location -Properties $property -ResourceName $resourceName -ResourceType $resourceType -ResourceGroupName $rg.ResourceGroupName -Force
447+
$existed = New-AzResource -Location $location -Properties $property -ResourceName $resourceName -ResourceType $resourceType -ResourceGroupName $rg.ResourceGroupName -Force
299448
}
300449

301450
return $resourceId
302451
}
452+
453+
<#
454+
.SYNOPSIS
455+
utility method to creare resource
456+
#>
457+
function NewTestResourcePurviewAccount
458+
{
459+
$rg = NewTestResourceGroup
460+
$resourceName = Get-ResourceName
461+
$resourceId = $rg.ResourceId + "/providers/Microsoft.Purview/accounts/" + $resourceName
462+
463+
$location = "westus"
464+
$property = @{test="test-tag"}
465+
$resourceType = "microsoft.purview/accounts"
466+
467+
$existed = Get-AzResource -ResourceId $resourceId -ErrorVariable notPresent -ErrorAction SilentlyContinue
468+
if ($notPresent) {
469+
$existed = New-AzPurviewAccount -Name $resourceName -ResourceGroupName $rg.ResourceGroupName -IdentityType SystemAssigned -Location $location -Tag $property -SkuCapacity 4 -SkuName Standard
470+
}
471+
472+
return $resourceId
473+
}

0 commit comments

Comments
 (0)