Skip to content

Commit 5300086

Browse files
committed
Add preliminary tests
1 parent 0d7b185 commit 5300086

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

templates/AppLockerProject/build/validate.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ param
1111

1212
Import-Module Pester
1313

14+
$global:testroot = Join-Path $ProjectRoot tests
1415
$po = [PesterConfiguration]::New()
15-
$po.Run.Path = Join-Path $ProjectRoot "tests/$TestType"
16+
$po.Run.Path = Join-Path $global:testroot $TestType
1617
$po.Run.PassThru = $true
1718
$po.Output.Verbosity = 'Detailed'
1819
$po.TestResult.Enabled = $true
19-
$po.TestResult.OutputPath = Join-Path $ProjectRoot 'testresults.xml'
20+
$po.TestResult.OutputPath = Join-Path $global:testroot 'testresults.xml'
2021
$po.TestResult.OutputFormat = 'NUnit2.5'
2122

2223
$result = Invoke-Pester -Configuration $po
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
BeforeDiscovery {
2+
$yamlFiles = Get-ChildItem -Path "$global:testroot\..\configurationdata" -Filter *.ym*l -Recurse -File | Foreach-Object {
3+
@{
4+
FullName = $_.FullName
5+
BaseName = $_.BaseName
6+
Name = $_.Name
7+
}
8+
}
9+
}
10+
11+
Describe "YAML file integrity" {
12+
It "<Name> Convert from YAML without errors" -TestCases $yamlFiles {
13+
{ Get-Content -Raw -Path $FullName | ConvertFrom-Yaml -ErrorAction Stop } | Should -Not -Throw
14+
}
15+
16+
It "<Name> Contains only valid rule types" -TestCases $yamlFiles {
17+
$types = 'Dll', 'Exe', 'Msi', 'Script', 'Appx'
18+
19+
$content = Get-Content -Raw -Path $FullName | ConvertFrom-Yaml -ErrorAction SilentlyContinue
20+
21+
if (-not $content.ContainsKey('RuleCollections'))
22+
{
23+
return
24+
}
25+
26+
$content.RuleCollections.Keys | Foreach-Object { $_ | Should -BeIn $types }
27+
}
28+
}

0 commit comments

Comments
 (0)