Skip to content

Commit 8007818

Browse files
feat: Added documentation for Bicep post-deployment tests (#713)
1 parent d6e743f commit 8007818

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

docs/content/specs/bicep/_index.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,3 +524,62 @@ Example - `AVM Module Issue template` module name entry for the Bicep resource m
524524
---
525525

526526
<br>
527+
528+
#### ID: BCPNFR16 - Category: Testing - Post-deployment tests
529+
530+
For each test case in the `e2e` folder, you can optionally add post-deployment Pester tests that are executed once the corresponding deployment completed and before the removal logic kicks in.
531+
532+
To leverage the feature you must
533+
- Use Pester as a test framework in each test file
534+
- Name the file with the suffix `"*.tests.ps1"`
535+
- Place each test file the `e2e` test's folder or any subfolder (e.g., `e2e/max/myTest.tests.ps1` or `e2e/max/tests/myTest.tests.ps1`)
536+
- Implement an input parameter `TestInputData` in the following way:
537+
```pwsh
538+
param (
539+
[Parameter(Mandatory = $false)]
540+
[hashtable] $TestInputData = @{}
541+
)
542+
```
543+
Through this parameter you can make use of every output the `main.test.bicep` file returns, as well as the path to the test template file in case you want to extract data from it directly.
544+
545+
For example, with an output such as `output resourceId string = testDeployment[1].outputs.resourceId` defined in the `main.test.bicep` file, the `$TestInputData` would look like
546+
```pwsh
547+
$TestInputData = @{
548+
DeploymentOutputs = @{
549+
resourceId = @{
550+
Type = "String"
551+
Value = "/subscriptions/***/resourceGroups/dep-***-keyvault.vaults-kvvpe-rg/providers/Microsoft.KeyVault/vaults/***kvvpe001"
552+
}
553+
}
554+
ModuleTestFolderPath = "/home/runner/work/bicep-registry-modules/bicep-registry-modules/avm/res/key-vault/vault/tests/e2e/private-endpoint"
555+
}
556+
```
557+
A full test file may look like
558+
559+
{{< expand "➕ Pester post-deployment test file example" "expand/collapse">}}
560+
561+
```pwsh
562+
param (
563+
[Parameter(Mandatory = $false)]
564+
[hashtable] $TestInputData = @{}
565+
)
566+
567+
Describe 'Validate private endpoint deployment' {
568+
569+
Context 'Validate sucessful deployment' {
570+
571+
It "Private endpoints should be deployed in resource group" {
572+
573+
$keyVaultResourceId = $TestInputData.DeploymentOutputs.resourceId.Value
574+
$testResourceGroup = ($keyVaultResourceId -split '\/')[4]
575+
$deployedPrivateEndpoints = Get-AzPrivateEndpoint -ResourceGroupName $testResourceGroup
576+
$deployedPrivateEndpoints.Count | Should -BeGreaterThan 0
577+
}
578+
}
579+
}
580+
```
581+
{{< /expand >}}
582+
583+
---
584+
585+
<br>

0 commit comments

Comments
 (0)