Instantly share code, notes, and snippets.

Embed
What would you like to do?
Testing ARM Templates with Pester
Param(
[string] [Parameter(Mandatory=$true)] $ResourceGroupName,
[string] [Parameter(Mandatory=$true)] $TemplateFile,
[hashtable] [Parameter(Mandatory=$true)] $Parameters
)
Describe "Logic App Deployment Tests" {
BeforeAll {
$DebugPreference = "Continue"
}
AfterAll {
$DebugPreference = "SilentlyContinue"
}
Context "When Logic App deployed without parameters" {
try {
$output = Test-AzureRmResourceGroupDeployment `
-ResourceGroupName $ResourceGroupName `
-TemplateFile $TemplateFile `
-logicAppName1 $null `
-logicAppName2 $null `
-ErrorAction Stop `
5>&1
}
catch {
$ex = $_.Exception | Format-List -Force
}
It "Should throw exception" {
$ex | Should -Not -Be $null
$ex.Message | Should -Not -Be ([string]::Empty)
}
}
Context "When Logic App deployed with parameters" {
$output = Test-AzureRmResourceGroupDeployment `
-ResourceGroupName $ResourceGroupName `
-TemplateFile $TemplateFile `
-TemplateParameterObject $Parameters `
-ErrorAction Stop `
5>&1
$result = (($output[32] -split "Body:")[1] | ConvertFrom-Json).properties
It "Should be deployed successfully" {
$result.provisioningState | Should -Be "Succeeded"
}
It "Should have name of" {
$expected = $Parameters.LogicAppName1 + "-" + $Parameters.LogicAppName2
$resource = $result.validatedResources[0]
$resource.name | Should -Be $expected
}
}
}
@badalk

This comment has been minimized.

badalk commented Aug 19, 2018

This is good if you have only 1 parameter file. Typically you will have multiple sets of parameter files because multiple combinations come into play (like any other application test scenario). Have you come across using -TestCases in "It" block and splatting it to iterate through each one to run Test-AzureRmResourceGroupDeployment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment