-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexemptionConfigurationsSyntaxTest.ps1
More file actions
73 lines (63 loc) · 2.88 KB
/
exemptionConfigurationsSyntaxTest.ps1
File metadata and controls
73 lines (63 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#Requires -Modules @{ModuleName="Pester"; ModuleVersion="5.3.1"}
#Requires -Version 7.0
<#
=======================================================================================================
AUTHOR: Tao Yang
DATE: 12/08/2025
NAME: exemptionConfigurationsSyntaxTest.ps1
VERSION: 1.0.0
COMMENT: Initiates the Pester tests for syntax validation of the Policy Exemption configuration files
=======================================================================================================
#>
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true, HelpMessage = 'Specify the Exemption Configurations file folder path.')]
[validateScript({ Test-Path $_ -PathType Container })]
[string]$configurationFilesPath,
[Parameter(Mandatory = $true)]
[validateScript({ Test-Path $_ -PathType leaf })]
[string]$configurationSchemaFilePath,
[Parameter(Mandatory = $false, HelpMessage = 'Specify the Pester test tags to exclude (comma separated).')]
[string]$ExcludeTags,
[Parameter(Mandatory = $true, HelpMessage = 'Specify the Pester test output folder path.')]
[ValidateNotNullOrEmpty()]
[string]$OutputFileDir,
[Parameter(Mandatory = $false, HelpMessage = 'Specify the Pester test output file prefix.')]
[ValidateNotNullOrEmpty()]
[string]$OutputFilePrefix = "TEST-ExemptionConfigurationSyntax",
[Parameter(Mandatory = $false, HelpMessage = 'Specify the Pester test output format.')]
[ValidateSet('NUnitXml', 'LegacyNUnitXML')]
[string]$OutputFormat = 'NUnitXml'
)
$testFilePath = join-path $PSScriptRoot "exemption.configurations.syntax.tests.ps1"
Write-Verbose "Exemption Configuration Files Path: '$configurationFilesPath'"
Write-Verbose "Testing '$testFilePath'..."
$testData = @{
configurationFilesPath = $configurationFilesPath
configurationSchemaFilePath = $configurationSchemaFilePath
}
$testContainer = New-PesterContainer -Path $testFilePath -Data $testData
$testConfig = New-PesterConfiguration
$testConfig.Run.Container = $testContainer
$testConfig.Run.PassThru = $true
$testConfig.Output.verbosity = 'Detailed'
if ($ExcludeTags.length -gt 0) {
$arrExcludedTags = @()
foreach ($item in $($ExcludeTags -split ',')) {
$arrExcludedTags += $($item.trim())
}
$testConfig.filter.ExcludeTag = $arrExcludedTags
}
$testResultFile = join-path $OutputFileDir "$OutputFilePrefix`.XML"
Write-Output "Result file for Exemption Configuration File Syntax test: $testResultFile"
$testConfig.TestResult.Enabled = $true
$testConfig.TestResult.TestSuiteName = 'ExemptionConfigurationSyntaxTests'
$testConfig.TestResult.OutputFormat = $OutputFormat
$testConfig.TestResult.OutputPath = $testResultFile
$testResult = Invoke-Pester -Configuration $testConfig
if ($testResult.TestResult.Result -ieq 'failed') {
Write-Error "Exemption Configuration File Syntax tests failed."
}
Write-Output "Current files in OutputFileDir '$OutputFileDir':"
Get-ChildItem -Path $OutputFileDir
Write-Output "Done"