Skip to content

Commit 9cc0eb7

Browse files
authored
Add smoke test for set a resource tag case (#11623)
* Add one smoke test for set a resource tag case. * Implement test case function.
1 parent 27e5a60 commit 9cc0eb7

File tree

3 files changed

+1638
-0
lines changed

3 files changed

+1638
-0
lines changed

src/Resources/Resources.Test/ScenarioTests/ResourceTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ public void TestSetAResourceTest()
103103
TestRunner.RunTestScript("Test-SetAResource");
104104
}
105105

106+
[Fact]
107+
[Trait(Category.AcceptanceType, Category.CheckIn)]
108+
public void TestSetAResourceTagCase()
109+
{
110+
TestRunner.RunTestScript("Test-SetAResourceTagCase");
111+
}
112+
106113
[Fact]
107114
[Trait(Category.AcceptanceType, Category.CheckIn)]
108115
public void TestSetAResourceUsingPiping()

src/Resources/Resources.Test/ScenarioTests/ResourceTests.ps1

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,4 +856,77 @@ function Test-RemoveASetOfResources
856856
Get-AzResource -ResourceName "*test*" -ResourceGroupName "*$rgname*" | Remove-AzResource -Force
857857
$expected = Get-AzResource -ResourceName "*test*" -ResourceGroupName "*$rgname*"
858858
Assert-Null $expected
859+
}
860+
861+
<#
862+
.SYNOPSIS
863+
Tests setting resource tags.
864+
.DESCRIPTION
865+
SmokeTest
866+
#>
867+
function Test-SetAResourceTagCase
868+
{
869+
# Setup
870+
$rgname = Get-ResourceGroupName
871+
$rname = Get-ResourceName
872+
$rglocation = Get-Location "Microsoft.Resources" "resourceGroups" "West US"
873+
$apiversion = "2014-04-01"
874+
$resourceType = "Providers.Test/statefulResources"
875+
876+
try
877+
{
878+
# Test
879+
New-AzResourceGroup -Name $rgname -Location $rglocation
880+
$resource = New-AzResource -Name $rname -Location $rglocation -Tags @{testtag = "testval"} -ResourceGroupName $rgname -ResourceType $resourceType -PropertyObject @{"key" = "value"} -SkuObject @{ Name = "A0" } -ApiVersion $apiversion -Force
881+
882+
# Verify tags and their casing
883+
# resource.Tags key is exactly "testtag" with case sensitive match
884+
Assert-True { $resource.Tags.ContainsKey("testtag") }
885+
Assert-True { !$resource.Tags.ContainsKey("TESTtag") }
886+
887+
Assert-True { $resource.Tags.testtag -ceq "testval" }
888+
Assert-True { $resource.Tags.testtag -cne "testVAL" }
889+
890+
# Set resource (add a new tag with key testTag2 = "TestVal2")
891+
Set-AzResource -Tags @{testtag = "testval"; testTag2 = "TestVal2"} -ResourceGroupName $rgname -ResourceName $rname -ResourceType $resourceType -Properties @{"key2" = "value2"} -Force
892+
Start-Sleep -s 30
893+
$resource = Get-AzResource -ResourceGroupName $rgname -ResourceName $rname -ResourceType $resourceType
894+
895+
# Verify tag keys
896+
Assert-True { $resource.Tags.ContainsKey("testtag") }
897+
Assert-True { !$resource.Tags.ContainsKey("TESTtag") }
898+
899+
Assert-True { $resource.Tags.ContainsKey("testTag2") }
900+
Assert-True { !$resource.Tags.ContainsKey("TestTag2") }
901+
902+
# Verify tag values
903+
Assert-True { $resource.Tags.testtag -ceq "testval" }
904+
Assert-True { $resource.Tags.testtag -cne "testVAL" }
905+
906+
Assert-True { $resource.Tags.testTag2 -ceq "TestVal2" }
907+
Assert-True { $resource.Tags.testTag2 -cne "testval2" }
908+
909+
# Set resource (replace tags with keys of different cases)
910+
Set-AzResource -Tags @{testTag = "testVAL"; testtag2 = "Testval2"} -ResourceGroupName $rgname -ResourceName $rname -ResourceType $resourceType -Properties @{"key2" = "value2"} -Force
911+
Start-Sleep -s 30
912+
$resource = Get-AzResource -ResourceGroupName $rgname -ResourceName $rname -ResourceType $resourceType
913+
914+
# Verify tag keys
915+
Assert-True { $resource.Tags.ContainsKey("testTag") }
916+
Assert-True { !$resource.Tags.ContainsKey("testtag") }
917+
918+
Assert-True { $resource.Tags.ContainsKey("testtag2") }
919+
Assert-True { !$resource.Tags.ContainsKey("testTag2") }
920+
921+
# Verify tag values
922+
Assert-True { $resource.Tags.testTag -ceq "testVAL" }
923+
Assert-True { $resource.Tags.testTag -cne "testval" }
924+
925+
Assert-True { $resource.Tags.testtag2 -ceq "Testval2" }
926+
Assert-True { $resource.Tags.testtag2 -cne "TestVal2" }
927+
}
928+
finally
929+
{
930+
Clean-ResourceGroup $rgname
931+
}
859932
}

src/Resources/Resources.Test/SessionRecords/Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ResourceTests/TestSetAResourceTagCase.json

Lines changed: 1558 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)