From cd37d29ea9e6d77eb96556a2b7fe82d8ed76176b Mon Sep 17 00:00:00 2001 From: AlexanderSehr Date: Sun, 29 Dec 2024 09:34:27 +0100 Subject: [PATCH 01/11] Added test for UDT nullable & array + support for PesterTags --- .../compliance/module.tests.ps1 | 46 ++++++++++++++++++- utilities/tools/Test-ModuleLocally.ps1 | 17 ++++++- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/utilities/pipelines/staticValidation/compliance/module.tests.ps1 b/utilities/pipelines/staticValidation/compliance/module.tests.ps1 index d6a0882b72..6d6b193014 100644 --- a/utilities/pipelines/staticValidation/compliance/module.tests.ps1 +++ b/utilities/pipelines/staticValidation/compliance/module.tests.ps1 @@ -631,7 +631,6 @@ Describe 'Module tests' -Tag 'Module' { $incorrectParameters | Should -BeNullOrEmpty -Because ('parameters in the template file should be camel-cased. Found incorrect items: [{0}].' -f ($incorrectParameters -join ', ')) } - It "[] Each parameters' & UDT's 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 $moduleFolderTestCases { param( @@ -1174,6 +1173,51 @@ Describe 'Module tests' -Tag 'Module' { $outputs | Should -Contain 'systemAssignedMIPrincipalId' } } + + Context 'UDT-spcific' { + + It '[] A UDT should not be of type array, but instead the parameter that uses it.' -TestCases $moduleFolderTestCases -Tag 'UDT' { + + param( + [hashtable] $templateFileContent + ) + + if (-not $templateFileContent.definitions) { + Set-ItResult -Skipped -Because 'the module template has no user-defined types.' + return + } + + $incorrectTypes = [System.Collections.ArrayList]@() + foreach ($type in $templateFileContent.definitions.Keys) { + if ($templateFileContent.definitions.$type.type -eq 'array') { + $incorrectTypes += $type + } + } + + $incorrectTypes | Should -BeNullOrEmpty -Because ('no user-defined type should be declared as an array, but instead the parameter that uses the type. This makes the template and its parameters easier to understand. Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) + } + + It '[] A UDT should not be nullable, but instead the parameter that uses it.' -TestCases $moduleFolderTestCases -Tag 'UDT' { + + param( + [hashtable] $templateFileContent + ) + + if (-not $templateFileContent.definitions) { + Set-ItResult -Skipped -Because 'the module template has no user-defined types.' + return + } + + $incorrectTypes = [System.Collections.ArrayList]@() + foreach ($type in $templateFileContent.definitions.Keys) { + if ($templateFileContent.definitions.$type.nullable -eq $true) { + $incorrectTypes += $type + } + } + + $incorrectTypes | Should -BeNullOrEmpty -Because ('no user-defined type should be declared as nullable, but instead the parameter that uses the type. This makes the template and its parameters easier to understand. Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) + } + } } } diff --git a/utilities/tools/Test-ModuleLocally.ps1 b/utilities/tools/Test-ModuleLocally.ps1 index 10791bc671..1989d69703 100644 --- a/utilities/tools/Test-ModuleLocally.ps1 +++ b/utilities/tools/Test-ModuleLocally.ps1 @@ -12,6 +12,9 @@ Mandatory. Path to the Bicep/ARM module that is being tested .PARAMETER ModuleTestFilePath Optional. Path to the template file/folder that is to be tested with the template file. Defaults to the module's default '.test' folder. Will be used if the DeploymentTest/ValidationTest switches are set. +.PARAMETER PesterTag +Optional. A string array that can be specified to run only Pester tests with the specified tag + .PARAMETER PesterTest Optional. A switch parameter that triggers a Pester test for the module @@ -135,6 +138,10 @@ function Test-ModuleLocally { [Parameter(Mandatory = $false)] [hashtable] $AdditionalTokens = @{}, + [Parameter(Mandatory = $false)] + [Alias('PesterTags')] + [string[]] $PesterTag, + [Parameter(Mandatory = $false)] [switch] $PesterTest, @@ -186,7 +193,7 @@ function Test-ModuleLocally { } } - Invoke-Pester -Configuration @{ + $configuration = @{ Run = @{ Container = New-PesterContainer -Path $testFiles -Data @{ repoRootPath = $repoRootPath @@ -197,6 +204,14 @@ function Test-ModuleLocally { Verbosity = 'Detailed' } } + + if (-not [String]::IsNullOrEmpty($PesterTag)) { + $configuration['Filter'] = @{ + Tag = $PesterTag + } + } + + Invoke-Pester -Configuration $configuration } catch { $PSItem.Exception.Message } From c166fc365a3ebbb4208ddf777db3fcd27a50018e Mon Sep 17 00:00:00 2001 From: AlexanderSehr Date: Sun, 29 Dec 2024 09:49:18 +0100 Subject: [PATCH 02/11] Update to latest --- .../compliance/module.tests.ps1 | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/utilities/pipelines/staticValidation/compliance/module.tests.ps1 b/utilities/pipelines/staticValidation/compliance/module.tests.ps1 index 6d6b193014..0e9226fcf3 100644 --- a/utilities/pipelines/staticValidation/compliance/module.tests.ps1 +++ b/utilities/pipelines/staticValidation/compliance/module.tests.ps1 @@ -1217,6 +1217,27 @@ Describe 'Module tests' -Tag 'Module' { $incorrectTypes | Should -BeNullOrEmpty -Because ('no user-defined type should be declared as nullable, but instead the parameter that uses the type. This makes the template and its parameters easier to understand. Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) } + + It '[] A UDT should always end wth the suffix "Type".' -TestCases $moduleFolderTestCases -Tag 'UDT' { + + param( + [hashtable] $templateFileContent + ) + + if (-not $templateFileContent.definitions) { + Set-ItResult -Skipped -Because 'the module template has no user-defined types.' + return + } + + $incorrectTypes = [System.Collections.ArrayList]@() + foreach ($typeName in $templateFileContent.definitions.Keys) { + if ($typeName -notmatch '.+Type$') { + $incorrectTypes += $typeName + } + } + + $incorrectTypes | Should -BeNullOrEmpty -Because ('every used-defined type should end with the suffix "Type". Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) + } } } } From f966f16090c5952226224fbc7371828d70f83670 Mon Sep 17 00:00:00 2001 From: AlexanderSehr Date: Sun, 29 Dec 2024 09:54:52 +0100 Subject: [PATCH 03/11] Update to latest --- .../pipelines/staticValidation/compliance/module.tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utilities/pipelines/staticValidation/compliance/module.tests.ps1 b/utilities/pipelines/staticValidation/compliance/module.tests.ps1 index 0e9226fcf3..f79c6364cb 100644 --- a/utilities/pipelines/staticValidation/compliance/module.tests.ps1 +++ b/utilities/pipelines/staticValidation/compliance/module.tests.ps1 @@ -1231,7 +1231,7 @@ Describe 'Module tests' -Tag 'Module' { $incorrectTypes = [System.Collections.ArrayList]@() foreach ($typeName in $templateFileContent.definitions.Keys) { - if ($typeName -notmatch '.+Type$') { + if ($typeName -cnotmatch '.+Type$') { $incorrectTypes += $typeName } } From 699fc249b5e0762700d7a95600c1f6229c3b6501 Mon Sep 17 00:00:00 2001 From: AlexanderSehr Date: Sun, 29 Dec 2024 09:56:40 +0100 Subject: [PATCH 04/11] Added spec ref --- .../pipelines/staticValidation/compliance/module.tests.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utilities/pipelines/staticValidation/compliance/module.tests.ps1 b/utilities/pipelines/staticValidation/compliance/module.tests.ps1 index f79c6364cb..77fa9f73e8 100644 --- a/utilities/pipelines/staticValidation/compliance/module.tests.ps1 +++ b/utilities/pipelines/staticValidation/compliance/module.tests.ps1 @@ -1176,7 +1176,7 @@ Describe 'Module tests' -Tag 'Module' { Context 'UDT-spcific' { - It '[] A UDT should not be of type array, but instead the parameter that uses it.' -TestCases $moduleFolderTestCases -Tag 'UDT' { + It '[] A UDT should not be of type array, but instead the parameter that uses it. AVM-Spec-Ref: BCPNFR18.' -TestCases $moduleFolderTestCases -Tag 'UDT' { param( [hashtable] $templateFileContent @@ -1197,7 +1197,7 @@ Describe 'Module tests' -Tag 'Module' { $incorrectTypes | Should -BeNullOrEmpty -Because ('no user-defined type should be declared as an array, but instead the parameter that uses the type. This makes the template and its parameters easier to understand. Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) } - It '[] A UDT should not be nullable, but instead the parameter that uses it.' -TestCases $moduleFolderTestCases -Tag 'UDT' { + It '[] A UDT should not be nullable, but instead the parameter that uses it. AVM-Spec-Ref: BCPNFR18.' -TestCases $moduleFolderTestCases -Tag 'UDT' { param( [hashtable] $templateFileContent @@ -1218,7 +1218,7 @@ Describe 'Module tests' -Tag 'Module' { $incorrectTypes | Should -BeNullOrEmpty -Because ('no user-defined type should be declared as nullable, but instead the parameter that uses the type. This makes the template and its parameters easier to understand. Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) } - It '[] A UDT should always end wth the suffix "Type".' -TestCases $moduleFolderTestCases -Tag 'UDT' { + It '[] A UDT should always end wth the suffix "Type". AVM-Spec-Ref: BCPNFR19.' -TestCases $moduleFolderTestCases -Tag 'UDT' { param( [hashtable] $templateFileContent From 9f56df676ee0a6a2a3e1bbb694bbcf17a067dead Mon Sep 17 00:00:00 2001 From: AlexanderSehr Date: Sun, 29 Dec 2024 23:19:42 +0100 Subject: [PATCH 05/11] Update to latest --- .../pipelines/staticValidation/compliance/module.tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utilities/pipelines/staticValidation/compliance/module.tests.ps1 b/utilities/pipelines/staticValidation/compliance/module.tests.ps1 index 77fa9f73e8..e16010f395 100644 --- a/utilities/pipelines/staticValidation/compliance/module.tests.ps1 +++ b/utilities/pipelines/staticValidation/compliance/module.tests.ps1 @@ -1218,7 +1218,7 @@ Describe 'Module tests' -Tag 'Module' { $incorrectTypes | Should -BeNullOrEmpty -Because ('no user-defined type should be declared as nullable, but instead the parameter that uses the type. This makes the template and its parameters easier to understand. Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) } - It '[] A UDT should always end wth the suffix "Type". AVM-Spec-Ref: BCPNFR19.' -TestCases $moduleFolderTestCases -Tag 'UDT' { + It '[] A UDT should always be camel-cased and end with the suffix "Type". AVM-Spec-Ref: BCPNFR19.' -TestCases $moduleFolderTestCases -Tag 'UDT' { param( [hashtable] $templateFileContent @@ -1231,7 +1231,7 @@ Describe 'Module tests' -Tag 'Module' { $incorrectTypes = [System.Collections.ArrayList]@() foreach ($typeName in $templateFileContent.definitions.Keys) { - if ($typeName -cnotmatch '.+Type$') { + if ($typeName -cnotmatch '^[a-z].+Type$') { $incorrectTypes += $typeName } } From 6bd6e533dd460910748be79ce81f8ed267d8a10b Mon Sep 17 00:00:00 2001 From: AlexanderSehr Date: Sun, 29 Dec 2024 23:21:34 +0100 Subject: [PATCH 06/11] Update to latest --- .../pipelines/staticValidation/compliance/module.tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utilities/pipelines/staticValidation/compliance/module.tests.ps1 b/utilities/pipelines/staticValidation/compliance/module.tests.ps1 index e16010f395..257bb9f2f2 100644 --- a/utilities/pipelines/staticValidation/compliance/module.tests.ps1 +++ b/utilities/pipelines/staticValidation/compliance/module.tests.ps1 @@ -1231,12 +1231,12 @@ Describe 'Module tests' -Tag 'Module' { $incorrectTypes = [System.Collections.ArrayList]@() foreach ($typeName in $templateFileContent.definitions.Keys) { - if ($typeName -cnotmatch '^[a-z].+Type$') { + if ($typeName -cnotmatch '^[a-z].*Type$') { $incorrectTypes += $typeName } } - $incorrectTypes | Should -BeNullOrEmpty -Because ('every used-defined type should end with the suffix "Type". Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) + $incorrectTypes | Should -BeNullOrEmpty -Because ('every used-defined type should be camel-cased and end with the suffix "Type". Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) } } } From c24ef4dc8d5b2a37dc06d20237a21390e281a45d Mon Sep 17 00:00:00 2001 From: AlexanderSehr Date: Fri, 17 Jan 2025 17:09:05 +0100 Subject: [PATCH 07/11] Updated failing tests to mere warnings --- .../compliance/module.tests.ps1 | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/utilities/pipelines/staticValidation/compliance/module.tests.ps1 b/utilities/pipelines/staticValidation/compliance/module.tests.ps1 index 257bb9f2f2..bb05790395 100644 --- a/utilities/pipelines/staticValidation/compliance/module.tests.ps1 +++ b/utilities/pipelines/staticValidation/compliance/module.tests.ps1 @@ -1193,8 +1193,11 @@ Describe 'Module tests' -Tag 'Module' { $incorrectTypes += $type } } - - $incorrectTypes | Should -BeNullOrEmpty -Because ('no user-defined type should be declared as an array, but instead the parameter that uses the type. This makes the template and its parameters easier to understand. Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) + # To be re-enabled once more modules are prepared. The code right below can then be removed. + # $incorrectTypes | Should -BeNullOrEmpty -Because ('no user-defined type should be declared as an array, but instead the parameter that uses the type. This makes the template and its parameters easier to understand. Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) + $warningMessage = ('No user-defined type should be declared as an array, but instead the parameter that uses the type. This makes the template and its parameters easier to understand. Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) + Write-Warning $warningMessage + Set-ItResult -Skipped -Because $warningMessage } It '[] A UDT should not be nullable, but instead the parameter that uses it. AVM-Spec-Ref: BCPNFR18.' -TestCases $moduleFolderTestCases -Tag 'UDT' { @@ -1215,7 +1218,11 @@ Describe 'Module tests' -Tag 'Module' { } } - $incorrectTypes | Should -BeNullOrEmpty -Because ('no user-defined type should be declared as nullable, but instead the parameter that uses the type. This makes the template and its parameters easier to understand. Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) + # To be re-enabled once more modules are prepared. The code right below can then be removed. + # $incorrectTypes | Should -BeNullOrEmpty -Because ('no user-defined type should be declared as nullable, but instead the parameter that uses the type. This makes the template and its parameters easier to understand. Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) + $warningMessage = ('No user-defined type should be declared as nullable, but instead the parameter that uses the type. This makes the template and its parameters easier to understand. Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) + Write-Warning $warningMessage + Set-ItResult -Skipped -Because $warningMessage } It '[] A UDT should always be camel-cased and end with the suffix "Type". AVM-Spec-Ref: BCPNFR19.' -TestCases $moduleFolderTestCases -Tag 'UDT' { @@ -1236,7 +1243,11 @@ Describe 'Module tests' -Tag 'Module' { } } - $incorrectTypes | Should -BeNullOrEmpty -Because ('every used-defined type should be camel-cased and end with the suffix "Type". Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) + # To be re-enabled once more modules are prepared. The code right below can then be removed. + # $incorrectTypes | Should -BeNullOrEmpty -Because ('every used-defined type should be camel-cased and end with the suffix "Type". Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) + $warningMessage = ('Every used-defined type should be camel-cased and end with the suffix "Type". Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) + Write-Warning $warningMessage + Set-ItResult -Skipped -Because $warningMessage } } } From c31608153cc763054e96457b6324035b81cf3f70 Mon Sep 17 00:00:00 2001 From: AlexanderSehr Date: Fri, 17 Jan 2025 20:45:21 +0100 Subject: [PATCH 08/11] Fixed output --- .../compliance/module.tests.ps1 | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/utilities/pipelines/staticValidation/compliance/module.tests.ps1 b/utilities/pipelines/staticValidation/compliance/module.tests.ps1 index bb05790395..691e7667fc 100644 --- a/utilities/pipelines/staticValidation/compliance/module.tests.ps1 +++ b/utilities/pipelines/staticValidation/compliance/module.tests.ps1 @@ -1197,6 +1197,10 @@ Describe 'Module tests' -Tag 'Module' { # $incorrectTypes | Should -BeNullOrEmpty -Because ('no user-defined type should be declared as an array, but instead the parameter that uses the type. This makes the template and its parameters easier to understand. Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) $warningMessage = ('No user-defined type should be declared as an array, but instead the parameter that uses the type. This makes the template and its parameters easier to understand. Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) Write-Warning $warningMessage + + Write-Output @{ + Warning = $warningMessage + } Set-ItResult -Skipped -Because $warningMessage } @@ -1222,6 +1226,10 @@ Describe 'Module tests' -Tag 'Module' { # $incorrectTypes | Should -BeNullOrEmpty -Because ('no user-defined type should be declared as nullable, but instead the parameter that uses the type. This makes the template and its parameters easier to understand. Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) $warningMessage = ('No user-defined type should be declared as nullable, but instead the parameter that uses the type. This makes the template and its parameters easier to understand. Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) Write-Warning $warningMessage + + Write-Output @{ + Warning = $warningMessage + } Set-ItResult -Skipped -Because $warningMessage } @@ -1247,6 +1255,10 @@ Describe 'Module tests' -Tag 'Module' { # $incorrectTypes | Should -BeNullOrEmpty -Because ('every used-defined type should be camel-cased and end with the suffix "Type". Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) $warningMessage = ('Every used-defined type should be camel-cased and end with the suffix "Type". Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) Write-Warning $warningMessage + + Write-Output @{ + Warning = $warningMessage + } Set-ItResult -Skipped -Because $warningMessage } } @@ -1622,8 +1634,12 @@ Describe 'API version tests' -Tag 'ApiCheck' { if ($approvedApiVersions -notcontains $TargetApi) { # Using a warning now instead of an error, as we don't want to block PRs for this. - Write-Warning ("The used API version [$TargetApi] is not one of the most recent 5 versions. Please consider upgrading to one of the following: {0}" -f $approvedApiVersions -join ', ') + $warningMessage = "The used API version [$TargetApi] is not one of the most recent 5 versions. Please consider upgrading to one of the following: {0}" -f ($approvedApiVersions -join ', ') + Write-Warning $warningMessage + Write-Output @{ + Warning = $warningMessage + } # The original failed test was # $approvedApiVersions | Should -Contain $TargetApi } else { @@ -1640,7 +1656,13 @@ Describe 'API version tests' -Tag 'ApiCheck' { if ($indexOfVersion -gt ($approvedApiVersions.Count - 2)) { $newerAPIVersions = $approvedApiVersions[0..($indexOfVersion - 1)] - Write-Warning ("The used API version [$TargetApi] for Resource Type [$ProviderNamespace/$ResourceType] will soon expire. Please consider updating it. Consider using one of the newer API versions [{0}]" -f ($newerAPIVersions -join ', ')) + + $warningMessage = "The used API version [$TargetApi] for Resource Type [$ProviderNamespace/$ResourceType] will soon expire. Please consider updating it. Consider using one of the newer API versions [{0}]" -f ($newerAPIVersions -join ', ') + Write-Warning $warningMessage + + Write-Output @{ + Warning = $warningMessage + } } } } From 49147b39bb19511f74c9ab3799df12af81378e7c Mon Sep 17 00:00:00 2001 From: AlexanderSehr Date: Fri, 17 Jan 2025 20:55:42 +0100 Subject: [PATCH 09/11] Update to latest --- .../compliance/module.tests.ps1 | 42 ++++++++++++------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/utilities/pipelines/staticValidation/compliance/module.tests.ps1 b/utilities/pipelines/staticValidation/compliance/module.tests.ps1 index 691e7667fc..baa8930088 100644 --- a/utilities/pipelines/staticValidation/compliance/module.tests.ps1 +++ b/utilities/pipelines/staticValidation/compliance/module.tests.ps1 @@ -1195,13 +1195,17 @@ Describe 'Module tests' -Tag 'Module' { } # To be re-enabled once more modules are prepared. The code right below can then be removed. # $incorrectTypes | Should -BeNullOrEmpty -Because ('no user-defined type should be declared as an array, but instead the parameter that uses the type. This makes the template and its parameters easier to understand. Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) - $warningMessage = ('No user-defined type should be declared as an array, but instead the parameter that uses the type. This makes the template and its parameters easier to understand. Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) - Write-Warning $warningMessage + if ($incorrectTypes.Count -gt 0) { + $warningMessage = ('No user-defined type should be declared as an array, but instead the parameter that uses the type. This makes the template and its parameters easier to understand. Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) + Write-Warning $warningMessage - Write-Output @{ - Warning = $warningMessage + Write-Output @{ + Warning = $warningMessage + } + Set-ItResult -Skipped -Because $warningMessage + } else { + $true | Should -Be $true } - Set-ItResult -Skipped -Because $warningMessage } It '[] A UDT should not be nullable, but instead the parameter that uses it. AVM-Spec-Ref: BCPNFR18.' -TestCases $moduleFolderTestCases -Tag 'UDT' { @@ -1224,13 +1228,17 @@ Describe 'Module tests' -Tag 'Module' { # To be re-enabled once more modules are prepared. The code right below can then be removed. # $incorrectTypes | Should -BeNullOrEmpty -Because ('no user-defined type should be declared as nullable, but instead the parameter that uses the type. This makes the template and its parameters easier to understand. Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) - $warningMessage = ('No user-defined type should be declared as nullable, but instead the parameter that uses the type. This makes the template and its parameters easier to understand. Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) - Write-Warning $warningMessage + if ($incorrectTypes.Count -gt 0) { + $warningMessage = ('No user-defined type should be declared as nullable, but instead the parameter that uses the type. This makes the template and its parameters easier to understand. Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) + Write-Warning $warningMessage - Write-Output @{ - Warning = $warningMessage + Write-Output @{ + Warning = $warningMessage + } + Set-ItResult -Skipped -Because $warningMessage + } else { + $true | Should -Be $true } - Set-ItResult -Skipped -Because $warningMessage } It '[] A UDT should always be camel-cased and end with the suffix "Type". AVM-Spec-Ref: BCPNFR19.' -TestCases $moduleFolderTestCases -Tag 'UDT' { @@ -1253,13 +1261,17 @@ Describe 'Module tests' -Tag 'Module' { # To be re-enabled once more modules are prepared. The code right below can then be removed. # $incorrectTypes | Should -BeNullOrEmpty -Because ('every used-defined type should be camel-cased and end with the suffix "Type". Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) - $warningMessage = ('Every used-defined type should be camel-cased and end with the suffix "Type". Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) - Write-Warning $warningMessage + if ($incorrectTypes.Count -gt 0) { + $warningMessage = ('Every used-defined type should be camel-cased and end with the suffix "Type". Found incorrect items: [{0}].' -f ($incorrectTypes -join ', ')) + Write-Warning $warningMessage - Write-Output @{ - Warning = $warningMessage + Write-Output @{ + Warning = $warningMessage + } + Set-ItResult -Skipped -Because $warningMessage + } else { + $true | Should -Be $true } - Set-ItResult -Skipped -Because $warningMessage } } } From aa12e55142202d7b2ea737a6739f6e060796206c Mon Sep 17 00:00:00 2001 From: AlexanderSehr Date: Fri, 17 Jan 2025 21:10:21 +0100 Subject: [PATCH 10/11] Update to latest --- .../staticValidation/compliance/module.tests.ps1 | 9 --------- 1 file changed, 9 deletions(-) diff --git a/utilities/pipelines/staticValidation/compliance/module.tests.ps1 b/utilities/pipelines/staticValidation/compliance/module.tests.ps1 index baa8930088..6bfd55aaa2 100644 --- a/utilities/pipelines/staticValidation/compliance/module.tests.ps1 +++ b/utilities/pipelines/staticValidation/compliance/module.tests.ps1 @@ -1202,9 +1202,6 @@ Describe 'Module tests' -Tag 'Module' { Write-Output @{ Warning = $warningMessage } - Set-ItResult -Skipped -Because $warningMessage - } else { - $true | Should -Be $true } } @@ -1235,9 +1232,6 @@ Describe 'Module tests' -Tag 'Module' { Write-Output @{ Warning = $warningMessage } - Set-ItResult -Skipped -Because $warningMessage - } else { - $true | Should -Be $true } } @@ -1268,9 +1262,6 @@ Describe 'Module tests' -Tag 'Module' { Write-Output @{ Warning = $warningMessage } - Set-ItResult -Skipped -Because $warningMessage - } else { - $true | Should -Be $true } } } From 43e61ef191b0ef27455919e3322e8c7ba0bf5054 Mon Sep 17 00:00:00 2001 From: AlexanderSehr Date: Sat, 18 Jan 2025 10:24:16 +0100 Subject: [PATCH 11/11] Update to latest --- utilities/tools/Test-ModuleLocally.ps1 | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/utilities/tools/Test-ModuleLocally.ps1 b/utilities/tools/Test-ModuleLocally.ps1 index 1989d69703..662d56dd8b 100644 --- a/utilities/tools/Test-ModuleLocally.ps1 +++ b/utilities/tools/Test-ModuleLocally.ps1 @@ -37,7 +37,6 @@ Optional. Additional parameters you can provide with the deployment. E.g. @{ res Optional. A hashtable parameter that contains custom tokens to be replaced in the paramter files for deployment .EXAMPLE - $TestModuleLocallyInput = @{ TemplateFilePath = 'C:\network\route-table\main.bicep' ModuleTestFilePath = 'C:\network\route-table\.test\common\main.test.bicep' @@ -62,7 +61,16 @@ Test-ModuleLocally @TestModuleLocallyInput -Verbose Run a Test-Az*Deployment using a test file with the provided tokens .EXAMPLE +$TestModuleLocallyInput = @{ + TemplateFilePath = 'C:\network\route-table\main.bicep' + PesterTest = $true + PesterTag = 'UDT' +} +Test-ModuleLocally @TestModuleLocallyInput -Verbose + +Run the Pester tests with Tag 'UDT' for the given template file +.EXAMPLE $TestModuleLocallyInput = @{ TemplateFilePath = 'C:\network\route-table\main.bicep' PesterTest = $true @@ -72,7 +80,6 @@ Test-ModuleLocally @TestModuleLocallyInput -Verbose Run all Pester tests for the given template file .EXAMPLE - $TestModuleLocallyInput = @{ TemplateFilePath = 'C:\network\route-table\main.bicep' PesterTest = $true