Skip to content

Commit

Permalink
feat: Added more AVM compliance tests & enabled us to add warnings to…
Browse files Browse the repository at this point in the history
… test cases (#606)

## Description

- Added test cases
- `If template has [<parameterName>] parameter, it should implement the
user-defined type [<udtName>]`
- `If a [managedIdentitiesType] UDT definition exists and supports
system-assigned-identities, the template should have an output for its
principal ID.`
  - `If a [tags] parameter exists it should be nullable.`
  - `Bicep test deployment files should contain serviceShort parameter`
- `Bicep test deployment files in a [default] folder should contain a
service short with ending [min]`
- `Bicep test deployment files in a [max] folder should contain a
service short with ending [max]`
- `Bicep test deployment files in a [waf-aligned] folder should contain
a service short with ending [waf]`
  - `Bicep test deployment files should contain a test name`
  - `Bicep test deployment files should contain a test description`
- `Bicep test deployment files should contain namePrefix parameter with
value ['#_namePrefix_#']`
- Cleanup in pester script that removes support for `main.json` test
cases
- Enabled passing warnings into the GitHub Pester result


![image](https://github.com/Azure/bicep-registry-modules/assets/5365358/417511b1-5f5c-43cc-ba3f-8879ccdcb189)

| Pipeline |
| - | 
|
[![avm.res.key-vault.vault](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.key-vault.vault.yml/badge.svg?branch=users%2Falsehr%2FtestFileCompliance)](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.key-vault.vault.yml)
|
|
[![avm.res.batch.batch-account](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.batch.batch-account.yml/badge.svg?branch=users%2Falsehr%2FtestFileCompliance)](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.batch.batch-account.yml)
|
|
[![avm.res.cognitive-services.account](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.cognitive-services.account.yml/badge.svg?branch=users%2Falsehr%2FtestFileCompliance)](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.cognitive-services.account.yml)
|
|
[![avm.res.compute.ssh-public-key](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.compute.ssh-public-key.yml/badge.svg?branch=users%2Falsehr%2FtestFileCompliance)](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.compute.ssh-public-key.yml)
|
|
[![avm.res.insights.action-group](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.insights.action-group.yml/badge.svg?branch=users%2Falsehr%2FtestFileCompliance)](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.insights.action-group.yml)
|
|
[![avm.res.kubernetes-configuration.extension](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.kubernetes-configuration.extension.yml/badge.svg?branch=users%2Falsehr%2FtestFileCompliance)](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.kubernetes-configuration.extension.yml)
|
|
[![avm.res.kubernetes-configuration.flux-configuration](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.kubernetes-configuration.flux-configuration.yml/badge.svg?branch=users%2Falsehr%2FtestFileCompliance)](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.kubernetes-configuration.flux-configuration.yml)
|
|
[![avm.res.network.dns-forwarding-ruleset](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.network.dns-forwarding-ruleset.yml/badge.svg?branch=users%2Falsehr%2FtestFileCompliance)](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.network.dns-forwarding-ruleset.yml)
|
|
[![avm.res.network.dns-resolver](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.network.dns-resolver.yml/badge.svg?branch=users%2Falsehr%2FtestFileCompliance)](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.network.dns-resolver.yml)
|
|
[![avm.res.network.dns-zone](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.network.dns-zone.yml/badge.svg?branch=users%2Falsehr%2FtestFileCompliance)](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.network.dns-zone.yml)
|
|
[![avm.res.network.network-interface](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.network.network-interface.yml/badge.svg?branch=users%2Falsehr%2FtestFileCompliance)](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.network.network-interface.yml)
|
|
[![avm.res.network.private-dns-zone](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.network.private-dns-zone.yml/badge.svg?branch=users%2Falsehr%2FtestFileCompliance)](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.network.private-dns-zone.yml)
|
|
[![avm.res.network.private-endpoint](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.network.private-endpoint.yml/badge.svg?branch=users%2Falsehr%2FtestFileCompliance)](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.network.private-endpoint.yml)
|
|
[![avm.res.network.public-ip-address](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.network.public-ip-address.yml/badge.svg?branch=users%2Falsehr%2FtestFileCompliance)](https://github.com/AlexanderSehr/bicep-registry-modules/actions/workflows/avm.res.network.public-ip-address.yml)
|

> [explicit
ref](https://github.com/AlexanderSehr/bicep-registry-modules/actions/runs/6802984967)

---------

Co-authored-by: Erika Gressi <[email protected]>
  • Loading branch information
AlexanderSehr and eriqua authored Nov 14, 2023
1 parent ecf069c commit 0ea942e
Show file tree
Hide file tree
Showing 8 changed files with 367 additions and 114 deletions.
2 changes: 1 addition & 1 deletion avm/res/cognitive-services/account/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ module account 'br/public:avm/res/cognitive-services/account:<version>' = {

### Example 6: _WAF-aligned_

This instance deploys the module in alignment with the best-pratices of the Well-Architectured-Framework.
This instance deploys the module in alignment with the best-practices of the Azure Well-Architected Framework.


<details>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
targetScope = 'subscription'

metadata name = 'WAF-aligned'
metadata description = 'This instance deploys the module in alignment with the best-pratices of the Well-Architectured-Framework.'
metadata description = 'This instance deploys the module in alignment with the best-practices of the Azure Well-Architected Framework.'

// ========== //
// Parameters //
Expand Down
21 changes: 15 additions & 6 deletions avm/res/insights/action-group/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ The following section provides usage examples for the module, which were used to
>**Note**: To reference the module, please use the following syntax `br/public:avm/res/insights/action-group:<version>`.
- [Defaults](#example-1-defaults)
- [Max](#example-2-max)
- [Waf-Aligned](#example-3-waf-aligned)
- [Using only defaults](#example-1-using-only-defaults)
- [Using large parameter set](#example-2-using-large-parameter-set)
- [WAF-aligned](#example-3-waf-aligned)

### Example 1: _Using only defaults_

This instance deploys the module with the minimum set of required parameters.

### Example 1: _Defaults_

<details>

Expand Down Expand Up @@ -126,7 +129,10 @@ module actionGroup 'br/public:avm/res/insights/action-group:<version>' = {
</details>
<p>

### Example 2: _Max_
### Example 2: _Using large parameter set_

This instance deploys the module with most of its features enabled.


<details>

Expand Down Expand Up @@ -245,7 +251,10 @@ module actionGroup 'br/public:avm/res/insights/action-group:<version>' = {
</details>
<p>

### Example 3: _Waf-Aligned_
### Example 3: _WAF-aligned_

This instance deploys the module in alignment with the best-practices of the Azure Well-Architected Framework.


<details>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
targetScope = 'subscription'

metadata name = 'Using only defaults'
metadata description = 'This instance deploys the module with the minimum set of required parameters.'

// ========== //
// Parameters //
// ========== //
Expand Down
3 changes: 3 additions & 0 deletions avm/res/insights/action-group/tests/e2e/max/main.test.bicep
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
targetScope = 'subscription'

metadata name = 'Using large parameter set'
metadata description = 'This instance deploys the module with most of its features enabled.'

// ========== //
// Parameters //
// ========== //
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
targetScope = 'subscription'

metadata name = 'WAF-aligned'
metadata description = 'This instance deploys the module in alignment with the best-practices of the Azure Well-Architected Framework.'

// ========== //
// Parameters //
// ========== //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,12 @@ function Set-PesterGitHubOutput {
$passedTests = $PesterTestResults.Passed
$failedTests = $PesterTestResults.Failed
$skippedTests = $PesterTestResults.Skipped
$testsWithWarnings = ($passedTests + $failedTests + $skippedTests) | Where-Object { $_.StandardOutput.Keys -eq 'Warning' }

Write-Verbose ('Formatting [{0}] passed tests' -f $passedTests.Count)
Write-Verbose ('Formatting [{0}] failed tests' -f $failedTests.Count)
Write-Verbose ('Formatting [{0}] skipped tests' -f $skippedTests.Count)
Write-Verbose ('Formatting [{0}] tests with explicit warnings' -f $warnings.Count)

######################
# Set output content #
Expand All @@ -98,9 +100,9 @@ function Set-PesterGitHubOutput {

## Header table
$fileContent += [System.Collections.ArrayList]@(
'| Total No. of Processed Tests| Passed Tests :white_check_mark: | Failed Tests :x: | Skipped Tests :paperclip: |',
'| :-- | :-- | :-- | :-- |'
('| {0} | {1} | {2} | {3} |' -f $PesterTestResults.TotalCount, $passedTests.count , $failedTests.count, $skippedTests.count),
'| Total No. of Processed Tests| Passed Tests :white_check_mark: | Failed Tests :x: | Skipped Tests :paperclip: | Tests with warnings :warning: |',
'| :-- | :-- | :-- | :-- | :-- |',
('| {0} | {1} | {2} | {3} | {4} |' -f $PesterTestResults.TotalCount, $passedTests.count , $failedTests.count, $skippedTests.count, $testsWithWarnings.count),
''
)

Expand All @@ -125,11 +127,11 @@ function Set-PesterGitHubOutput {

$intermediateNameElements = $failedTest.Path
$intermediateNameElements[-1] = '**{0}**' -f $failedTest.ExpandedName
$testName = (($intermediateNameElements -join ' / ' | Out-String) -replace '\|', '\|').Trim()
$testName = ((($intermediateNameElements -join ' / ' | Out-String) -replace '\|', '\|') -replace '_', '\_').Trim()

$errorTestLine = $failedTest.ErrorRecord.TargetObject.Line
$errorTestFile = (($failedTest.ErrorRecord.TargetObject.File -split '[\/|\\](avm[\/|\\])')[-2, -1] -join '') -replace '\\', '/' # e.g., [avm\res\cognitive-services\account\tests\unit\custom.tests.ps1]
$errorMessage = $failedTest.ErrorRecord.TargetObject.Message.Trim() -replace '\n', '<br>' # Replace new lines with <br> to enable line breaks in markdown
$errorMessage = ($failedTest.ErrorRecord.TargetObject.Message.Trim() -replace '_', '\_') -replace '\n', '<br>' # Replace new lines with <br> to enable line breaks in markdown

$testReference = '{0}:{1}' -f (Split-Path $errorTestFile -Leaf), $errorTestLine

Expand All @@ -140,8 +142,7 @@ function Set-PesterGitHubOutput {

$fileContent += '| {0} | {1} | <code>{2}</code> |' -f $testName, $errorMessage, $testReference
}
}
else {
} else {
$fileContent += ('No tests failed.')
}

Expand Down Expand Up @@ -172,7 +173,7 @@ function Set-PesterGitHubOutput {

$intermediateNameElements = $passedTest.Path
$intermediateNameElements[-1] = '**{0}**' -f $passedTest.ExpandedName
$testName = (($intermediateNameElements -join ' / ' | Out-String) -replace '\|', '\|').Trim()
$testName = ((($intermediateNameElements -join ' / ' | Out-String) -replace '\|', '\|') -replace '_', '\_').Trim()

$testLine = $passedTest.ScriptBlock.StartPosition.StartLine
$testFile = (($passedTest.ScriptBlock.File -split '[\/|\\](avm[\/|\\])')[-2, -1] -join '') -replace '\\', '/' # e.g., [avm\res\cognitive-services\account\tests\unit\custom.tests.ps1]
Expand All @@ -185,8 +186,7 @@ function Set-PesterGitHubOutput {

$fileContent += '| {0} | <code>{1}</code> |' -f $testName, $testReference
}
}
else {
} else {
$fileContent += ('No tests passed.')
}

Expand Down Expand Up @@ -218,12 +218,12 @@ function Set-PesterGitHubOutput {

$intermediateNameElements = $skippedTest.Path
$intermediateNameElements[-1] = '**{0}**' -f $skippedTest.ExpandedName
$testName = (($intermediateNameElements -join ' / ' | Out-String) -replace '\|', '\|').Trim()
$testName = ((($intermediateNameElements -join ' / ' | Out-String) -replace '\|', '\|') -replace '_', '\_').Trim()

$reason = ('Test {0}' -f $skippedTest.ErrorRecord.Exception.Message -replace '\|', '\|').Trim()

$testLine = $passedTest.ScriptBlock.StartPosition.StartLine
$testFile = (($passedTest.ScriptBlock.File -split '[\/|\\](avm[\/|\\])')[-2, -1] -join '') -replace '\\', '/' # e.g., [avm\res\cognitive-services\account\tests\unit\custom.tests.ps1]
$testLine = $skippedTest.ScriptBlock.StartPosition.StartLine
$testFile = (($skippedTest.ScriptBlock.File -split '[\/|\\](avm[\/|\\])')[-2, -1] -join '') -replace '\\', '/' # e.g., [avm\res\cognitive-services\account\tests\unit\custom.tests.ps1]

$testReference = '{0}:{1}' -f (Split-Path $testFile -Leaf), $testLine
if (-not [String]::IsNullOrEmpty($GitHubRepository) -and -not [String]::IsNullOrEmpty($BranchName)) {
Expand All @@ -233,8 +233,7 @@ function Set-PesterGitHubOutput {

$fileContent += '| {0} | {1} | <code>{2}</code> |' -f $testName, $reason, $testReference
}
}
else {
} else {
$fileContent += ('No tests were skipped.')
}

Expand All @@ -244,6 +243,52 @@ function Set-PesterGitHubOutput {
''
)

##################
## Warnings ##
##################

Write-Verbose 'Adding warnings'
$fileContent += [System.Collections.ArrayList]@(
'',
'<details>',
'<summary>List of explicit warnings</summary>',
''
)

if ($testsWithWarnings.Count -gt 0) {

$fileContent += [System.Collections.ArrayList]@(
'| Name | Warning | Source |',
'| :-- | :-- | :-- |'
)
foreach ($test in ($testsWithWarnings | Sort-Object -Property { $PSItem.ExpandedName }) ) {
foreach ($warning in $test.StandardOutput.Warning) {
$intermediateNameElements = $test.Path
$intermediateNameElements[-1] = '**{0}**' -f $test.ExpandedName
$testName = ((($intermediateNameElements -join ' / ' | Out-String) -replace '\|', '\|') -replace '_', '\_').Trim()

$testLine = $test.ScriptBlock.StartPosition.StartLine
$testFile = (($test.ScriptBlock.File -split '[\/|\\](avm[\/|\\])')[-2, -1] -join '') -replace '\\', '/' # e.g., [avm\res\cognitive-services\account\tests\unit\custom.tests.ps1]

$testReference = '{0}:{1}' -f (Split-Path $testFile -Leaf), $testLine
if (-not [String]::IsNullOrEmpty($GitHubRepository) -and -not [String]::IsNullOrEmpty($BranchName)) {
# Creating URL to test file to enable users to 'click' on it
$testReference = "[$testReference](https://github.com/$GitHubRepository/blob/$BranchName/$testFile#L$testLine)"
}

$fileContent += ('| {0} | {1} | <code>{2}</code> |' -f $testName, $warning, $testReference)
}
}
} else {
$fileContent += ('No tests with warnings.')
}

$fileContent += [System.Collections.ArrayList]@(
'',
'</details>',
''
)

if ($PSCmdlet.ShouldProcess("Test results file in path [$OutputFilePath]", 'Create')) {
$null = New-Item -Path $OutputFilePath -Force -Value ($fileContent | Out-String)
}
Expand Down
Loading

0 comments on commit 0ea942e

Please sign in to comment.