-
Notifications
You must be signed in to change notification settings - Fork 979
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH Workflow update for Policy Testing (#1538)
- Loading branch information
1 parent
cb1b176
commit ea3724f
Showing
4 changed files
with
74 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
Import-Module -Name $PSScriptRoot\PolicyPesterTestHelper.psm1 -Force -Verbose | ||
Import-Module Pester -Force | ||
|
||
function RunPester | ||
{ | ||
param ( | ||
[Parameter()] | ||
[String]$PolicyTest | ||
) | ||
|
||
$pesterConfiguration = @{ | ||
Run = @{ | ||
Container = New-PesterContainer -Path $PolicyTest | ||
PassThru = $true | ||
} | ||
Output = @{ | ||
Verbosity = 'Detailed' | ||
CIFormat = 'Auto' | ||
} | ||
} | ||
$result = Invoke-Pester -Configuration $pesterConfiguration | ||
#exit $result.FailedCount | ||
} | ||
|
||
$ModifiedFiles = @(Get-PolicyFiles -DiffFilter "M") | ||
if ([String]::IsNullOrEmpty($ModifiedFiles)) | ||
{ | ||
Write-Warning "These are the modified policies: $($ModifiedFiles)" | ||
} | ||
else | ||
{ | ||
Write-Warning "There are no modified policies" | ||
} | ||
|
||
$AddedFiles = @(Get-PolicyFiles -DiffFilter "A") | ||
if ([String]::IsNullOrEmpty($AddedFiles)) | ||
{ | ||
Write-Warning "These are the added policies: $($AddedFiles)" | ||
} | ||
else | ||
{ | ||
Write-Warning "There are no added policies" | ||
} | ||
|
||
$ModifiedAddedFiles = $ModifiedFiles + $AddedFiles | ||
|
||
$ModifiedAddedFiles | ForEach-Object { | ||
|
||
$PolicyFile = Split-Path $_ -Leaf | ||
$PolicyFileClean = $PolicyFile -replace ".json", "" | ||
|
||
$testPath = "tests/policy/$($PolicyFileClean).Tests.ps1" | ||
|
||
if (Test-Path $testPath) | ||
{ | ||
Write-Warning "Running pester tests on $PolicyFileClean" | ||
RunPester($testPath) | ||
} | ||
else | ||
{ | ||
Write-Warning "There are no tests for $PolicyFileClean" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters