Skip to content

Instantly share code, notes, and snippets.

@justinyoo
Last active July 8, 2018 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinyoo/1e7c3e7f0e282c822c94206778557897 to your computer and use it in GitHub Desktop.
Save justinyoo/1e7c3e7f0e282c822c94206778557897 to your computer and use it in GitHub Desktop.
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