Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
dcff842
Fixed what-if funcationality with -QueryString parameter
Xynoclafe Feb 24, 2021
c608cd3
Added/Modified test cases for -QueryString
Xynoclafe Feb 26, 2021
39c53f0
Suppress credscan (credentials are invalid/for deleted resources)
Xynoclafe Mar 2, 2021
7731a98
include storage module in tests
Xynoclafe Mar 4, 2021
313600d
Remove scenario test and add mock test for -QueryString scenarios
Xynoclafe Mar 11, 2021
3fe7d81
Merge branch 'master' of https://github.com/Azure/azure-powershell in…
Xynoclafe Mar 11, 2021
971ec2c
Update changelog
Xynoclafe Mar 11, 2021
7df85e4
Fix build issues; Switch a mock test for a scenario test
Xynoclafe Mar 12, 2021
1584bea
Merge branch 'master' of https://github.com/Azure/azure-powershell in…
Xynoclafe Mar 12, 2021
0f681c6
Merge branch 'master' into xynoclafe/whatIfQueryString
wyunchi-ms Mar 15, 2021
fa42dd3
Replace myget with Azure artifacts (#14543)
dingmeng-xue Mar 16, 2021
18614a8
Fix credscan file
Xynoclafe Mar 16, 2021
36d8201
Update Cloud Shell image in README.md (#14531)
Mar 16, 2021
9639ca0
Fix merge
Xynoclafe Mar 16, 2021
acaf849
Normalized -QueryString starting with ? for scenarios involving dynam…
Xynoclafe Mar 16, 2021
45c4600
Merge branch 'release-2021-03-23' into xynoclafe/whatIfQueryString
wyunchi-ms Mar 17, 2021
8853e83
Merge branch 'release-2021-03-23' into xynoclafe/whatIfQueryString
wyunchi-ms Mar 17, 2021
dc1a2f5
Merge branch 'release-2021-03-23' into xynoclafe/whatIfQueryString
wyunchi-ms Mar 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public DeploymentWhatIf ToDeploymentWhatIf()
else if (Uri.IsWellFormedUriString(this.TemplateUri, UriKind.Absolute))
{
properties.TemplateLink = new TemplateLink(this.TemplateUri);

if (!string.IsNullOrEmpty(this.QueryString))
{
properties.TemplateLink.QueryString = this.QueryString;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed a test case

}
}
else
{
Expand Down
7 changes: 7 additions & 0 deletions src/Resources/Resources.Test/ScenarioTests/DeploymentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,12 @@ public void TestTestDeploymentFromBicepFile()
{
TestRunner.RunTestScript("Test-TestDeploymentFromBicepFile");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestWhatIfWithQueryString()
{
TestRunner.RunTestScript("Test-WhatIfWithQueryString");
}
}
}
84 changes: 81 additions & 3 deletions src/Resources/Resources.Test/ScenarioTests/DeploymentTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -797,17 +797,36 @@ function Test-NewDeploymentWithQueryString
# Setup
$rgname = Get-ResourceGroupName
$rname = Get-ResourceName
$saname = "querystringpstests"
$rglocation = "West US 2"
$subId = (Get-AzContext).Subscription.SubscriptionId

try
{
# Prepare our RG and basic template spec:

# Prepare our RG
New-AzResourceGroup -Name $rgname -Location $rglocation

#Prepare our Storage Account
$account = New-AzStorageAccount -ResourceGroupName $rgname -AccountName $saname -Location $rglocation -SkuName "Standard_LRS"

#Get StorageAccountKey
$key = (Get-AzStorageAccountKey -ResourceGroupName $rgname -AccountName $saname)| Where-Object {$_.KeyName -eq "key1"}

#Get StorageAccount context
$context = New-AzStorageContext -StorageAccountName $saname -StorageAccountKey $key.Value

#Create FileShare
New-AzStorageShare -Name "querystringshare" -Context $context

#Upload files to the StorageAccount
Set-AzStorageFileContent -ShareName "querystringshare" -Source "sampleLinkedTemplateParent.json" -Path "sampleLinkedTemplateParent.json" -Context $context
Set-AzStorageFileContent -ShareName "querystringshare" -Source "sampleLinkedTemplateChild.json" -Path "sampleLinkedTemplateChild.json" -Context $context

#Get SAStoken
$token = New-AzStorageAccountSASToken -Service File -ResourceType Service,Container,Object -Permission "r" -Context $context -ExpiryTime (Get-Date).AddMinutes(2)

#Create deployment
$deployment =New-AzResourceGroupDeployment -Name $rname -ResourceGroupName $rgname -TemplateUri "https://querystringtesting.blob.core.windows.net/testqsblob/linkedTemplateParent.json" -QueryString "foo"
$deployment =New-AzResourceGroupDeployment -Name $rname -ResourceGroupName $rgname -TemplateUri "https://querystringpstests.file.core.windows.net/querystringshare/sampleLinkedTemplateParent.json" -QueryString $token.Substring(1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this URL valid? I cannot access it in my environment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are urls for a storage account created during the test and deleted after it is completed. So you will not be able to access it outside of the test. But at the time of the test execution (recording), the urls are valid.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yunchi Wang (@wyunchi-ms) any idea on what is happening with this error?


# Assert
Assert-AreEqual Succeeded $deployment.ProvisioningState
Expand All @@ -816,6 +835,7 @@ function Test-NewDeploymentWithQueryString
finally
{
# Cleanup
Remove-AzStorageAccount -Force -ResourceGroupName $rgname -Name $saname;
Clean-ResourceGroup $rgname
}
}
Expand Down Expand Up @@ -884,4 +904,62 @@ function Test-TestDeploymentFromBicepFile
# Cleanup
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Tests what-if on a deployment from a template in a storage account using a query string.
#>
function Test-WhatIfWithQueryString
{
# Setup
$rgname = Get-ResourceGroupName
$rname = Get-ResourceName
$saname = "querystringpstests"
$rglocation = "West US 2"
$subId = (Get-AzContext).Subscription.SubscriptionId

try
{
# Prepare our RG
New-AzResourceGroup -Name $rgname -Location $rglocation

#Prepare our Storage Account
$account = New-AzStorageAccount -ResourceGroupName $rgname -AccountName $saname -Location $rglocation -SkuName "Standard_LRS"

#Get StorageAccountKey
$key = (Get-AzStorageAccountKey -ResourceGroupName $rgname -AccountName $saname)| Where-Object {$_.KeyName -eq "key1"}

#Get StorageAccount context
$context = New-AzStorageContext -StorageAccountName $saname -StorageAccountKey $key.Value

#Create FileShare
New-AzStorageShare -Name "querystringshare" -Context $context

#Upload files to the StorageAccount
Set-AzStorageFileContent -ShareName "querystringshare" -Source "sampleLinkedTemplateParent.json" -Path "sampleLinkedTemplateParent.json" -Context $context
Set-AzStorageFileContent -ShareName "querystringshare" -Source "sampleLinkedTemplateChild.json" -Path "sampleLinkedTemplateChild.json" -Context $context

#Get SAStoken
$token = New-AzStorageAccountSASToken -Service File -ResourceType Service,Container,Object -Permission "r" -Context $context -ExpiryTime (Get-Date).AddMinutes(3)

#Create deployment
$deployment =New-AzResourceGroupDeployment -Name $rname -ResourceGroupName $rgname -TemplateUri "https://querystringpstests.file.core.windows.net/querystringshare/sampleLinkedTemplateParent.json" -QueryString $token.Substring(1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this URL valid? I cannot access it in my environment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same reasoning as the comment below


# Assert
Assert-AreEqual Succeeded $deployment.ProvisioningState

#Run What-if
$result = New-AzResourceGroupDeployment -Name $rname -ResourceGroupName $rgname -TemplateUri "https://querystringpstests.file.core.windows.net/querystringshare/sampleLinkedTemplateParent.json" -QueryString $token.Substring(1) -WhatIf

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this URL valid? I cannot access it in my environment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same reasoning as the comment below


#assert that nothing has changed.
Assert-AreEqual 0 ($result).Count
}

finally
{
# Cleanup
Remove-AzStorageAccount -Force -ResourceGroupName $rgname -Name $saname;
Clean-ResourceGroup $rgname
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ protected ResourceTestRunner(ITestOutputHelper output)
.WithExtraRmModules(helper => new[]
{
helper.RMResourceModule,
helper.GetRMModulePath("AzureRM.Monitor.psd1")
helper.GetRMModulePath("AzureRM.Monitor.psd1"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add helper.GetRMModulePath("AzureRM.Storage.psd1"), here to use cmdlets in Storage when running test cases.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yunchi Wang (@wyunchi-ms) I made the suggested changes, but now it fails with "Device not configured"

helper.GetRMModulePath("AzureRM.Storage.psd1")
})
.WithRecordMatcher(
(ignoreResourcesClient, resourceProviders, userAgentsToIgnore) =>
Expand Down
Loading