Skip to content

Commit

Permalink
Add policyDefinitionReferenceId duplication test (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyconsulting authored May 9, 2024
1 parent c24df51 commit 41ee16b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ coverage.xml
testResults.xml
.DS_Store
*.test.xml
*test*.xml
*TEST*.xml
2 changes: 1 addition & 1 deletion AzPolicyTest/AzPolicyTest.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package>
<metadata>
<id>AzPolicyTest</id>
<version>2.3.2</version>
<version>2.4.0</version>
<authors>Tao Yang</authors>
<owners>TY Consulting Pty Ltd</owners>
<description>Provides pre-defined pester tests for Azure Policy and Initiative definitions</description>
Expand Down
Binary file modified AzPolicyTest/AzPolicyTest.psd1
Binary file not shown.
18 changes: 16 additions & 2 deletions AzPolicyTest/policySetDefStructure.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ Param (
[Parameter(Mandatory = $false)][string[]]$excludePath
)
Write-Verbose "Path: '$Path'"

function CountPolicyDefinitionReferenceId {
param(
[object] $policySetObject,
[string] $policyDefinitionReferenceId
)
$policy = $policySetObject.properties.policyDefinitions | where-object {$_.policyDefinitionReferenceId -ieq $policyDefinitionReferenceId}
$policy.count
}
function IsParameterInUse {
param(
[object] $policySetObject,
Expand Down Expand Up @@ -304,6 +311,7 @@ Foreach ($file in $files) {

$policyDefinitionTestCase = @{
policyDefinition = $policyDefinition
policyDefinitionReferenceIdCount = CountPolicyDefinitionReferenceId -policySetObject $json -policyDefinitionReferenceId $policyDefinition.policyDefinitionReferenceId
}

It "$policyDefTestTitle must contain 'policyDefinitionId' element" -TestCases $policyDefinitionTestCase -Tag 'PolicyDefinitionIdExists' {
Expand Down Expand Up @@ -333,7 +341,13 @@ Foreach ($file in $files) {
)
$policyDefinition.policyDefinitionReferenceId.length | Should -BeGreaterThan 0
}

It "'policyDefinitionReferenceId' in $policyDefTestTitle must be only used One (1) time" -TestCases $policyDefinitionTestCase -Tag 'noDuplicatePolicyDefinitionReferenceId' {
param(
[object] $policyDefinition,
[int]$policyDefinitionReferenceIdCount
)
$policyDefinitionReferenceIdCount | Should -Be 1
}
It "$policyDefTestTitle must contain 'parameters' element" -TestCases $policyDefinitionTestCase -Tag 'PolicyDefinitionParameterExists' {
param(
[object] $policyDefinition
Expand Down

0 comments on commit 41ee16b

Please sign in to comment.