Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
357c72d
Fixed readme
AlexanderSehr May 21, 2022
d546a44
Merge branch 'main' of https://github.com/Azure/ResourceModules
AlexanderSehr May 24, 2022
51d558c
Merge branch 'main' of https://github.com/Azure/ResourceModules
AlexanderSehr May 25, 2022
577129f
Flipped image build deployment
AlexanderSehr May 25, 2022
e520258
Merge branch 'main' of https://github.com/Azure/ResourceModules
AlexanderSehr May 26, 2022
ba93d7a
Merge branch 'main' of https://github.com/Azure/ResourceModules
AlexanderSehr May 27, 2022
3a26718
Merge branch 'main' of https://github.com/Azure/ResourceModules
AlexanderSehr May 29, 2022
3564e81
Undid param change
AlexanderSehr May 29, 2022
4a27ee8
Merge branch 'main' of https://github.com/Azure/ResourceModules
AlexanderSehr May 29, 2022
8650932
Merge branch 'main' of https://github.com/Azure/ResourceModules
AlexanderSehr May 29, 2022
419783d
Merge branch 'main' of https://github.com/Azure/ResourceModules
AlexanderSehr May 31, 2022
eccc238
Merge branch 'main' of https://github.com/Azure/ResourceModules
AlexanderSehr Jun 2, 2022
2621960
Merge branch 'main' of https://github.com/Azure/ResourceModules
AlexanderSehr Jun 3, 2022
9bb4c24
Merge branch 'main' of https://github.com/Azure/ResourceModules
AlexanderSehr Jun 3, 2022
411cd06
Implemented --no-restore for workaround
AlexanderSehr Jun 4, 2022
aebb1da
Regenerated readme
AlexanderSehr Jun 4, 2022
8831424
Merge branch 'main' of https://github.com/Azure/ResourceModules
AlexanderSehr Jun 4, 2022
edea8bd
Merge branch 'users/alsehr/1471_cliWorkaround' into users/alsehr/1473…
AlexanderSehr Jun 4, 2022
5a3c868
Exclude certain tests if no primary resource exists + updated skip be…
AlexanderSehr Jun 4, 2022
ffb0ec8
Adjusted test result search
AlexanderSehr Jun 4, 2022
474ffa3
Another try
AlexanderSehr Jun 4, 2022
1ca3900
Another try
AlexanderSehr Jun 4, 2022
cbc4557
Update to latest
AlexanderSehr Jun 4, 2022
57bb49d
Merge branch 'main' of https://github.com/Azure/ResourceModules
AlexanderSehr Jun 5, 2022
fd891bf
Merge branch 'main' into users/alsehr/1473_securityCenter
AlexanderSehr Jun 5, 2022
630457b
Merge branch 'main' of https://github.com/Azure/ResourceModules
AlexanderSehr Jun 6, 2022
82fa7f8
Merge branch 'main' of https://github.com/Azure/ResourceModules
AlexanderSehr Jun 6, 2022
96823d4
Merge branch 'main' of https://github.com/Azure/ResourceModules
AlexanderSehr Jun 6, 2022
1f2c0ee
Merge branch 'main' of https://github.com/Azure/ResourceModules
AlexanderSehr Jun 6, 2022
a4bff29
Merge branch 'main' of https://github.com/Azure/ResourceModules
AlexanderSehr Jun 7, 2022
ed550d3
Merged latest main
AlexanderSehr Jun 7, 2022
73c30ba
Added case handling
AlexanderSehr Jun 7, 2022
c597d99
Minor rename
AlexanderSehr Jun 7, 2022
0cfe407
Fixed spec
AlexanderSehr Jun 7, 2022
8d13d84
Specified all parm types
AlexanderSehr Jun 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions .github/actions/templates/validateModulePester/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,6 @@ runs:
}
}

Write-Output "::endgroup::"

- name: 'Publish Test Results'
uses: EnricoMi/publish-unit-test-result-action@v1
if: always() && !contains('cancelled,skipped', steps.pester_run_step.outcome)
with:
files: arm/.global/global-testResults.xml

# [Module Pester Test] task(s)
#-----------------------------
- name: 'Run API tests via Pester'
Expand Down Expand Up @@ -172,6 +164,6 @@ runs:

- name: 'Publish Test Results'
uses: EnricoMi/publish-unit-test-result-action@v1
if: always() && !contains('cancelled,skipped', steps.pester_api_run_step.outcome)
if: always()
with:
files: arm/.global/api-testResults.xml
files: 'arm/.global/*-testResults.xml'
131 changes: 79 additions & 52 deletions arm/.global/global.module.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Describe 'File/folder tests' -Tag Modules {
It '[<moduleFolderName>] folder should contain one or more *parameters.json files' -TestCases $folderTestCases {

param(
$moduleFolderName,
[string] $moduleFolderName,
$moduleFolderPath
)
$parameterFolderPath = Join-Path $moduleFolderPath '.parameters'
Expand All @@ -140,7 +140,7 @@ Describe 'File/folder tests' -Tag Modules {
It '[<moduleFolderName>] *parameters.json files in the .parameters folder should be valid json' -TestCases $parameterFolderFilesTestCases {

param(
$moduleFolderName,
[string] $moduleFolderName,
$parameterFilePath
)
(Get-Content $parameterFilePath) | ConvertFrom-Json
Expand Down Expand Up @@ -191,26 +191,34 @@ Describe 'Readme tests' -Tag Readme {
templateFilePath = $templateFilePath
readMeFilePath = Join-Path -Path $moduleFolderPath 'readme.md'
readMeContent = Get-Content (Join-Path -Path $moduleFolderPath 'readme.md')
isTopLevelModule = $moduleFolderPath.Replace('\', '/').Split('/arm/')[1].Split('/').Count -eq 2 # <provider>/<resourceType>
}
}

It '[<moduleFolderName>] Readme.md file should not be empty' -TestCases $readmeFolderTestCases {

param(
$moduleFolderName,
$readMeContent
[string] $moduleFolderName,
[object[]] $readMeContent
)
$readMeContent | Should -Not -Be $null
}

It '[<moduleFolderName>] Readme.md file should contain these sections in order: Navigation, Resource Types, Parameters, Outputs, Deployment examples' -TestCases $readmeFolderTestCases {

param(
$moduleFolderName,
$readMeContent
[string] $moduleFolderName,
[object[]] $readMeContent,
[boolean] $isTopLevelModule
)

$expectedHeadersInOrder = @('Navigation', 'Resource types', 'Parameters', 'Outputs', 'Deployment examples')
$expectedHeadersInOrder = @('Navigation', 'Resource types', 'Parameters', 'Outputs')

if ($isTopLevelModule) {
# Only top-level modules have parameter files and hence deployment examples
$expectedHeadersInOrder += 'Deployment examples'
}

$actualHeadersInOrder = $readMeContent | Where-Object { $_ -like '#*' } | ForEach-Object { ($_ -replace '#', '').TrimStart() }

$filteredActuals = $actualHeadersInOrder | Where-Object { $expectedHeadersInOrder -contains $_ }
Expand Down Expand Up @@ -382,7 +390,7 @@ Describe 'Readme tests' -Tag Readme {
It '[<moduleFolderName>] Outputs section should contain a table with these column names in order: Output Name, Type' -TestCases $readmeFolderTestCases {

param(
$moduleFolderName,
[string] $moduleFolderName,
$readMeContent
)

Expand Down Expand Up @@ -519,8 +527,8 @@ Describe 'Deployment template tests' -Tag Template {
It '[<moduleFolderName>] the template file should not be empty' -TestCases $deploymentFolderTestCases {

param(
$moduleFolderName,
$templateContent
[string] $moduleFolderName,
[hashtable] $templateContent
)
$templateContent | Should -Not -Be $null
}
Expand All @@ -529,8 +537,8 @@ Describe 'Deployment template tests' -Tag Template {
# the actual value changes depending on the scope of the template (RG, subscription, MG, tenant) !!
# https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-syntax
param(
$moduleFolderName,
$templateContent
[string] $moduleFolderName,
[hashtable] $templateContent
)

$Schemaverion = $templateContent.'$schema'
Expand All @@ -553,8 +561,8 @@ Describe 'Deployment template tests' -Tag Template {
It '[<moduleFolderName>] Template schema should use HTTPS reference' -TestCases $deploymentFolderTestCases {

param(
$moduleFolderName,
$templateContent
[string] $moduleFolderName,
[hashtable] $templateContent
)
$Schemaverion = $templateContent.'$schema'
($Schemaverion.Substring(0, 5) -eq 'https') | Should -Be $true
Expand All @@ -563,8 +571,8 @@ Describe 'Deployment template tests' -Tag Template {
It '[<moduleFolderName>] All apiVersion properties should be set to a static, hard-coded value' -TestCases $deploymentFolderTestCases {
#https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-best-practices
param(
$moduleFolderName,
$templateContent
[string] $moduleFolderName,
[hashtable] $templateContent
)
$ApiVersion = $templateContent.resources.apiVersion
$ApiVersionArray = @()
Expand All @@ -588,8 +596,8 @@ Describe 'Deployment template tests' -Tag Template {
It '[<moduleFolderName>] the template file should contain required elements: schema, contentVersion, resources' -TestCases $deploymentFolderTestCases {

param(
$moduleFolderName,
$templateContent
[string] $moduleFolderName,
[hashtable] $templateContent
)
$templateContent.Keys | Should -Contain '$schema'
$templateContent.Keys | Should -Contain 'contentVersion'
Expand All @@ -599,8 +607,8 @@ Describe 'Deployment template tests' -Tag Template {
It '[<moduleFolderName>] If delete lock is implemented, the template should have a lock parameter with the default value of []' -TestCases $deploymentFolderTestCases {

param(
$moduleFolderName,
$templateContent
[string] $moduleFolderName,
[hashtable] $templateContent
)
if ($lock = $templateContent.parameters.lock) {
$lock.Keys | Should -Contain 'defaultValue'
Expand All @@ -611,12 +619,12 @@ Describe 'Deployment template tests' -Tag Template {
It '[<moduleFolderName>] Parameter names should be camel-cased (no dashes or underscores and must start with lower-case letter)' -TestCases $deploymentFolderTestCases {

param(
$moduleFolderName,
$templateContent
[string] $moduleFolderName,
[hashtable] $templateContent
)

if (-not $templateContent.parameters) {
# Skip test
Set-ItResult -Skipped -Because 'the module template has no parameters.'
return
}

Expand All @@ -635,12 +643,12 @@ Describe 'Deployment template tests' -Tag Template {
It '[<moduleFolderName>] Variable names should be camel-cased (no dashes or underscores and must start with lower-case letter)' -TestCases $deploymentFolderTestCases {

param(
$moduleFolderName,
$templateContent
[string] $moduleFolderName,
[hashtable] $templateContent
)

if (-not $templateContent.variables) {
# Skip test
Set-ItResult -Skipped -Because 'the module template has no variables.'
return
}

Expand All @@ -660,8 +668,8 @@ Describe 'Deployment template tests' -Tag Template {
It '[<moduleFolderName>] Output names should be camel-cased (no dashes or underscores and must start with lower-case letter)' -TestCases $deploymentFolderTestCases {

param(
$moduleFolderName,
$templateContent
[string] $moduleFolderName,
[hashtable] $templateContent
)
$CamelCasingFlag = @()
$Outputs = $templateContent.outputs.Keys
Expand All @@ -679,8 +687,8 @@ Describe 'Deployment template tests' -Tag Template {
It '[<moduleFolderName>] CUA ID deployment should be present in the template' -TestCases $deploymentFolderTestCases {

param(
$moduleFolderName,
$templateContent
[string] $moduleFolderName,
[hashtable] $templateContent
)
$enableDefaultTelemetryFlag = @()
$Schemaverion = $templateContent.'$schema'
Expand All @@ -697,8 +705,8 @@ Describe 'Deployment template tests' -Tag Template {
It "[<moduleFolderName>] The Location should be defined as a parameter, with the default value of 'resourceGroup().Location' or global for ResourceGroup deployment scope" -TestCases $deploymentFolderTestCases {

param(
$moduleFolderName,
$templateContent
[string] $moduleFolderName,
[hashtable] $templateContent
)
$LocationFlag = $true
$Schemaverion = $templateContent.'$schema'
Expand All @@ -721,7 +729,7 @@ Describe 'Deployment template tests' -Tag Template {

param(
[string] $moduleFolderName,
$templateContent,
[hashtable] $templateContent,
[string] $templateFilePath
)

Expand All @@ -743,7 +751,7 @@ Describe 'Deployment template tests' -Tag Template {

param(
[string] $moduleFolderName,
$templateContent,
[hashtable] $templateContent,
[string] $templateFilePath
)

Expand All @@ -758,34 +766,52 @@ Describe 'Deployment template tests' -Tag Template {
It '[<moduleFolderName>] Resource name output should exist' -TestCases $deploymentFolderTestCases {

param(
$moduleFolderName,
$templateContent
[string] $moduleFolderName,
[hashtable] $templateContent,
$templateFilePath
)

# check if module contains a 'primary' resource we could draw a name from
$moduleResourceType = (Split-Path (($templateFilePath -replace '\\', '/') -split '/arm/')[1] -Parent) -replace '\\', '/'
if ($templateContent.resources.type -notcontains $moduleResourceType) {
Set-ItResult -Skipped -Because 'the module template has no primary resource to fetch a name from.'
return
}

# Otherwise test for standard outputs
$outputs = $templateContent.outputs.Keys
$outputs | Should -Contain 'name'
}

It '[<moduleFolderName>] Resource ID output should exist' -TestCases $deploymentFolderTestCases {

param(
$moduleFolderName,
$templateContent
[string] $moduleFolderName,
[hashtable] $templateContent,
$templateFilePath
)

# check if module contains a 'primary' resource we could draw a name from
$moduleResourceType = (Split-Path (($templateFilePath -replace '\\', '/') -split '/arm/')[1] -Parent) -replace '\\', '/'
if ($templateContent.resources.type -notcontains $moduleResourceType) {
Set-ItResult -Skipped -Because 'the module template has no primary resource to fetch a resource ID from.'
return
}

# Otherwise test for standard outputs
$outputs = $templateContent.outputs.Keys
$outputs | Should -Contain 'resourceId'
}

It "[<moduleFolderName>] parameters' description should start with a one word category starting with a capital letter, followed by a dot, a space and the actual description text ending with a dot." -TestCases $deploymentFolderTestCases {

param(
$moduleFolderName,
$templateContent
[string] $moduleFolderName,
[hashtable] $templateContent
)

if (-not $templateContent.parameters) {
# Skip test
Set-ItResult -Skipped -Because 'the module template has no parameters.'
return
}

Expand All @@ -803,12 +829,12 @@ Describe 'Deployment template tests' -Tag Template {
It "[<moduleFolderName>] Conditional parameters' description should contain 'Required if' followed by the condition making the parameter required." -TestCases $deploymentFolderTestCases {

param(
$moduleFolderName,
$templateContent
[string] $moduleFolderName,
[hashtable] $templateContent
)

if (-not $templateContent.parameters) {
# Skip test
Set-ItResult -Skipped -Because 'the module template has no parameters.'
return
}

Expand All @@ -830,12 +856,12 @@ Describe 'Deployment template tests' -Tag Template {
It "[<moduleFolderName>] outputs' description should start with a capital letter and contain text ending with a dot." -TestCases $deploymentFolderTestCases {

param(
$moduleFolderName,
$templateContent
[string] $moduleFolderName,
[hashtable] $templateContent
)

if (-not $templateContent.outputs) {
# Skip test
Set-ItResult -Skipped -Because 'the module template has no outputs.'
return
}

Expand Down Expand Up @@ -1023,12 +1049,13 @@ Describe "API version tests [All apiVersions in the template should be 'recent']
}

It 'In [<moduleName>] used resource type [<resourceType>] should use one of the recent API version(s). Currently using [<TargetApi>]' -TestCases $TestCases {

param(
$moduleName,
$resourceType,
$TargetApi,
$ProviderNamespace,
$AvailableApiVersions
[string] $moduleName,
[string] $resourceType,
[string] $TargetApi,
[string] $ProviderNamespace,
[object[]] $AvailableApiVersions
)

$namespaceResourceTypes = ($AvailableApiVersions | Where-Object { $_.ProviderNamespace -eq $ProviderNamespace }).ResourceTypes
Expand Down
12 changes: 6 additions & 6 deletions utilities/tools/Set-ModuleReadMe.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,10 @@ function Set-OutputsSection {

<#
.SYNOPSIS
Generate 'Usage Examples' for the ReadMe out of the parameter files currently used to test the template
Generate 'Deployment examples' for the ReadMe out of the parameter files currently used to test the template

.DESCRIPTION
Generate 'Usage Examples' for the ReadMe out of the parameter files currently used to test the template
Generate 'Deployment examples' for the ReadMe out of the parameter files currently used to test the template

.PARAMETER TemplateFileContent
Mandatory. The template file content object to crawl data from
Expand Down Expand Up @@ -607,15 +607,15 @@ function Set-ModuleReadMe {
'Outputs',
'Template references',
'Navigation',
'Usage examples'
'Deployment examples'
)]
[string[]] $SectionsToRefresh = @(
'Resource Types',
'Parameters',
'Outputs',
'Template references',
'Navigation',
'Usage examples'
'Deployment examples'
)
)

Expand Down Expand Up @@ -717,8 +717,8 @@ function Set-ModuleReadMe {
$readMeFileContent = Set-OutputsSection @inputObject
}

if ($SectionsToRefresh -contains 'Usage examples') {
# Handle [Usage examples] section
if ($SectionsToRefresh -contains 'Deployment examples') {
# Handle [Deployment examples] section
# ===================================
$inputObject = @{
ReadMeFileContent = $readMeFileContent
Expand Down