Skip to content

Commit

Permalink
Added test for telem passthru
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderSehr committed Feb 27, 2025
1 parent 175a8dc commit 7b61535
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion utilities/pipelines/staticValidation/compliance/module.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ Describe 'Module tests' -Tag 'Module' {
$telemetryDeploymentName | Should -Match "$expectedTelemetryIdentifier"
}

It '[<moduleFolderName>] Telemetry should be disabled for referenced modules with dedicated telemetry.' -TestCases ($moduleFolderTestCases | Where-Object { $_.moduleType -eq 'res' }) {
It '[<moduleFolderName>] For resource modules, telemetry should be disabled for referenced modules with dedicated telemetry.' -TestCases ($moduleFolderTestCases | Where-Object { $_.moduleType -eq 'res' }) {

param(
[hashtable] $templateFileContent,
Expand Down Expand Up @@ -1045,6 +1045,37 @@ Describe 'Module tests' -Tag 'Module' {

$incorrectCrossReferences | Should -BeNullOrEmpty -Because ('cross reference modules must be referenced with the enableTelemetry parameter set to the "enableReferencedModulesTelemetry" variable. Found incorrect items: [{0}].' -f ($incorrectCrossReferences -join ', '))
}

It '[<moduleFolderName>] For non-resource modules, telemetry configuration should be passed to referenced modules with dedicated telemetry.' -TestCases ($moduleFolderTestCases | Where-Object { $_.moduleType -ne 'res' }) {

param(
[hashtable] $templateFileContent,
[string] $templateFilePath
)

# get all referenced modules, that offer a telemetry parameter
$referencesWithTelemetry = $templateFileContent.resources.Values | Where-Object {
$_.type -eq 'Microsoft.Resources/deployments' -and
$_.properties.template.parameters.Keys -contains 'enableTelemetry'
}

if ($referencesWithTelemetry.Count -eq 0) {
Set-ItResult -Skipped -Because 'no modules with dedicated telemetry are deployed.'
return
}

# telemetry should be disabled for the referenced module
$incorrectCrossReferences = [System.Collections.ArrayList]@()
foreach ($referencedModule in $referencesWithTelemetry) {
if ($referencedModule.properties.parameters.Keys -notcontains 'enableTelemetry' -or
$referencedModule.properties.parameters.enableTelemetry.value -ne "[parameters('enableTelemetry')]") {
# remember the names (e.g. 'virtualNetwork_subnets') to provide a better error message
$incorrectCrossReferences.Add($referencedModule.identifier)
}
}

$incorrectCrossReferences | Should -BeNullOrEmpty -Because ('cross reference modules must be referenced with the enableTelemetry parameter set to the module''s own "enableTelemetry" parameter. Found incorrect items: [{0}].' -f ($incorrectCrossReferences -join ', '))
}
}

Context 'Output' {
Expand Down

0 comments on commit 7b61535

Please sign in to comment.