Skip to content

Commit

Permalink
Enhancement to Unit-Test-Policies workflow (#1402)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
Springstone and github-actions[bot] authored Aug 9, 2023
1 parent 687003e commit 236a023
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
26 changes: 25 additions & 1 deletion .github/actions-pester/Test-ModifiedPolicies.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,29 @@ Describe 'UnitTest-ModifiedPolicies' {
$PolicyMetadataVersion = $PolicyJson.properties.metadata.version
$PolicyJson = Get-Content -Path $_ -Raw | ConvertFrom-Json
Write-Warning "$($PolicyFile) - The current metadata version for the policy in the PR branch is : $($PolicyMetadataVersion)"
$PolicyMetadataVersion | Should -BeGreaterThan $PreviousPolicyDefinitionsFileVersion
if (!$PreviousPolicyDefinitionsFileVersion.EndsWith("deprecated")) {
$PolicyMetadataVersion | Should -BeGreaterThan $PreviousPolicyDefinitionsFileVersion
}
}
}

It "Check deprecated policy contains all required metadata" {
$ModifiedAddedFiles | ForEach-Object {
$PolicyJson = Get-Content -Path $_ -Raw | ConvertFrom-Json
$PolicyFile = Split-Path $_ -Leaf
$PolicyMetadataVersion = $PolicyJson.properties.metadata.version
Write-Warning "$($PolicyFile) - This is the policy metadata version: $($PolicyMetadataVersion)"
if ($PolicyMetadataVersion.EndsWith("deprecated")) {
Write-Warning "$($PolicyFile) - Should have the deprecated metadata flag set to true"
$PolicyMetadataDeprecated = $PolicyJson.properties.metadata.deprecated
$PolicyMetadataDeprecated | Should -BeTrue
Write-Warning "$($PolicyFile) - Should have the supersededBy metadata value set"
$PolicyMetadataSuperseded = $PolicyJson.properties.metadata.supersededBy
$PolicyMetadataSuperseded | Should -Not -BeNullOrEmpty
Write-Warning "$($PolicyFile) - [Deprecated] should be in the display name"
$PolicyPropertiesDisplayName = $PolicyJson.properties.displayName
$PolicyPropertiesDisplayName | Should -Match "[DEPRECATED]"
}
}
}

Expand Down Expand Up @@ -86,7 +108,9 @@ Describe 'UnitTest-ModifiedPolicies' {
$PolicyJson.properties.metadata.alzCloudEnvironments | Should -BeIn $AlzEnvironments
}
}

}

Context "Validate policy parameters" {
It 'Check for policy parameters have default values' {
$ModifiedAddedFiles | ForEach-Object {
Expand Down
Loading

0 comments on commit 236a023

Please sign in to comment.