Last active
July 8, 2018 15:20
-
-
Save justinyoo/1e7c3e7f0e282c822c94206778557897 to your computer and use it in GitHub Desktop.
Testing ARM Templates with Pester #2
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
{ | |
"error": null, | |
... | |
"properties": { | |
... | |
"validatedResources": [ | |
{ | |
"apiVersion": "2016-06-01", | |
"id": "...", | |
... | |
} | |
] | |
}, | |
... | |
} |
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
az group deployment validate ` | |
-g [RESOURCE_GROUP_NAME] ` | |
--template-file [TEMPLATE_FILE] ` | |
--parameters `@[TEMPLATE_PARAMETER_FILE] |
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
# 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 | |
} | |
} | |
} |
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
# 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