Testing ARM Templates with Pester
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?