Skip to content

Commit

Permalink
feat: Add VM AZ Parameter Test (#1334)
Browse files Browse the repository at this point in the history
## Description

This pull request primarily introduces a new unit test in the
`avm/res/compute/virtual-machine/tests/unit/az.tests.ps1` file. The unit
test ensures that the Availability Zone parameter in the VM Module does
not have a default value set.

Key changes include:

*
[`avm/res/compute/virtual-machine/tests/unit/az.tests.ps1`](diffhunk://#diff-709a50b14d616bcd12c7ca2e17421ba839293f79ba97d0bee05070ba38cadf56R1-R20):
Added a new parameter `$repoRootPath` which is optional. Also, added a
script to import the `Get-IsParameterRequired.ps1` helper script from
the shared scripts directory.
*
[`avm/res/compute/virtual-machine/tests/unit/az.tests.ps1`](diffhunk://#diff-709a50b14d616bcd12c7ca2e17421ba839293f79ba97d0bee05070ba38cadf56R1-R20):
Added a `BeforeAll` block that reads the content of `main.json` into a
hashtable.
*
[`avm/res/compute/virtual-machine/tests/unit/az.tests.ps1`](diffhunk://#diff-709a50b14d616bcd12c7ca2e17421ba839293f79ba97d0bee05070ba38cadf56R1-R20):
Introduced a new unit test under the `Describe` block titled
'Availability Zone Tests'. This test checks if the Availability Zone
parameter in the VM Module has a default value set. If it does, the test
fails.

## Pipeline Reference

<!-- Insert your Pipeline Status Badge below -->

| Pipeline |
| -------- |
|
[![avm.res.compute.virtual-machine](https://github.com/jtracey93/bicep-registry-modules/actions/workflows/avm.res.compute.virtual-machine.yml/badge.svg)](https://github.com/jtracey93/bicep-registry-modules/actions/workflows/avm.res.compute.virtual-machine.yml)
|

> Failure is expected as the module is currently not complaint

## Type of Change

<!-- Use the check-boxes [x] on the options that are relevant. -->

- [x] Update to CI Environment or utlities (Non-module effecting
changes)
- [ ] Azure Verified Module updates:
- [ ] Bugfix containing backwards compatible bug fixes, and I have NOT
bumped the MAJOR or MINOR version in `version.json`:
- [ ] Someone has opened a bug report issue, and I have included "Closes
#{bug_report_issue_number}" in the PR description.
- [ ] The bug was found by the module author, and no one has opened an
issue to report it yet.
- [ ] Feature update backwards compatible feature updates, and I have
bumped the MINOR version in `version.json`.
- [ ] Breaking changes and I have bumped the MAJOR version in
`version.json`.
  - [ ] Update to documentation

## Checklist

- [x] I'm sure there are no other open Pull Requests for the same
update/change
- [ ] I have run `Set-AVMModule` locally to generate the supporting
module files.
- [ ] My corresponding pipelines / checks run clean and green without
any errors or warnings

<!-- Please keep up to day with the contribution guide at
https://aka.ms/avm/contribute/bicep -->
  • Loading branch information
jtracey93 authored Mar 20, 2024
1 parent e04bf6a commit 2126fbd
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,5 @@
#/avm/ptn/avd-lza/networking/ @Azure/avm-ptn-avd-lza-networking-module-owners-bicep @Azure/avm-core-team-technical-bicep
#/avm/ptn/avd-lza/session-hosts/ @Azure/avm-ptn-avd-lza-sessionhosts-module-owners-bicep @Azure/avm-core-team-technical-bicep
#/avm/ptn/security/security-center/ @Azure/avm-ptn-securitycenter-module-owners-bicep @Azure/avm-core-team-technical-bicep

*avm.core.team.tests.ps1 @Azure/avm-core-team-technical-bicep
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ runs:
Run = @{
Container = New-PesterContainer -Path $testFiles -Data @{
moduleFolderPaths = $moduleFolderPaths
RepoRootPath = $env:GITHUB_WORKSPACE
}
PassThru = $true
}
Expand Down
40 changes: 40 additions & 0 deletions avm/res/compute/virtual-machine/tests/unit/avm.core.team.tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<#
.SYNOPSIS
This file contains Pester tests that the AVM Core Team has written for the module. Any additions or changes to these tests will need to be reviewed by the AVM Core Team, this is handled by CODEOWNERS.
If you wish to add your own Pester tests for you module create a new <something>.tests.ps1 file in the /tests/unit folder of your module.
#>

param (
[Parameter(Mandatory = $false)]
[array] $moduleFolderPaths,

[Parameter(Mandatory = $false)]
[string] $repoRootPath
)

BeforeAll {
. (Join-Path $RepoRootPath 'avm' 'utilities' 'pipelines' 'sharedScripts' 'helper' 'Get-IsParameterRequired.ps1')

if ($moduleFolderPaths.Count -gt 1) {
$topLevelModuleTemplatePath = $moduleFolderPaths | Sort-Object | Select-Object -First 1
}
else {
$topLevelModuleTemplatePath = $moduleFolderPaths
}

$moduleJsonContentHashtable = Get-Content -Path (Join-Path $topLevelModuleTemplatePath 'main.json') | ConvertFrom-Json -AsHashtable
}

Describe 'AVM Core Team Module Specific Tests' {

Context 'WAF - Reliability Pillar - Parameter Tests' {

It 'VM Module Availability Zone Parameter Should Not Have A Default Value Set' {
$isRequired = Get-IsParameterRequired -TemplateFileContent $moduleJsonContentHashtable -Parameter $moduleJsonContentHashtable.parameters.availabilityZone
$isRequired | Should -Be $true
}

}

}

0 comments on commit 2126fbd

Please sign in to comment.