Instantly share code, notes, and snippets.

Embed
What would you like to do?
Testing ARM Templates with Pester #2
{
"error": null,
...
"properties": {
...
"validatedResources": [
{
"apiVersion": "2016-06-01",
"id": "...",
...
}
]
},
...
}
az group deployment validate `
-g [RESOURCE_GROUP_NAME] `
--template-file [TEMPLATE_FILE] `
--parameters `@[TEMPLATE_PARAMETER_FILE]
# Extract of LogicApp.Tests.with.CLI.ps1
...
Describe "Logic App Deployment Tests" {
# Init
BeforeAll {
az login --service-principal -u $Username -p $Password -t $TenantId
}
# Teardown
AfterAll {
}
# Tests whether the cmdlet returns value or not.
Context "When Logic App deployed with parameters" {
$output = az group deployment validate `
-g $ResourceGroupName `
--template-file $SrcDirectory\LogicApp.json `
--parameters `@$SrcDirectory\LogicApp.parameters.json `
| ConvertFrom-Json
$result = $output.properties
It "Should be deployed successfully" {
$result.provisioningState | Should -Be "Succeeded"
}
It "Should have name of" {
$expected = "log-app"
$resource = $result.validatedResources[0]
$resource.name | Should -Be $expected
}
}
}
# Extract of Run-Pester.ps1
...
$segment = $TestFilePath.Split("\")
$testFile = $segment[$segment.Length - 1].Replace(".ps1", "");
$outputFile = "$OutputDirectory\TEST-$testFile-$BuildNumber.xml"
$parameters = @{ ResourceGroupName = $ResourceGroupName; SrcDirectory = $SrcDirectory; Username = $Username; Password = $Password; TenantId = $TenantId }
$script = @{ Path = $TestFilePath; Parameters = $parameters }
Invoke-Pester -Script $script -OutputFile $outputFile -OutputFormat NUnitXml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment