Skip to content

Commit 70b6148

Browse files
TrenlyCopilot
andauthored
Add Pester Tests for YamlCreate.InstallerDetection (#327538)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Trenly <12611259+Trenly@users.noreply.github.com>
1 parent 8018926 commit 70b6148

File tree

4 files changed

+535
-0
lines changed

4 files changed

+535
-0
lines changed

.github/workflows/pesterTests.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Pester Tests
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
paths:
8+
- "**/*.ps1"
9+
- "**/*.psm1"
10+
- "**/*.psd1"
11+
push:
12+
paths:
13+
- "**/*.ps1"
14+
- "**/*.psm1"
15+
- "**/*.psd1"
16+
17+
permissions:
18+
contents: read # Needed to check out the code
19+
pull-requests: read # Needed to read pull request details
20+
21+
jobs:
22+
test:
23+
runs-on: windows-latest
24+
steps:
25+
- name: Checkout code
26+
uses: actions/checkout@v3
27+
- name: Install Pester
28+
run: |
29+
# Pester 5.x is already included in Windows runners, but ensure latest version
30+
Install-Module -Name Pester -Force -SkipPublisherCheck -Scope CurrentUser -MinimumVersion 5.0.0
31+
- name: Run Pester Tests
32+
run: |
33+
# Find and run all Pester test files
34+
$testFiles = Get-ChildItem -Recurse -Filter *.Tests.ps1
35+
if ($testFiles) {
36+
Write-Host "Found $($testFiles.Count) test file(s)"
37+
foreach ($testFile in $testFiles) {
38+
Write-Host "Running tests in: $($testFile.FullName)"
39+
}
40+
41+
# Run all tests
42+
$config = New-PesterConfiguration
43+
$config.Run.Path = $testFiles.FullName
44+
$config.Run.Exit = $true
45+
$config.Output.Verbosity = 'Detailed'
46+
$config.TestResult.Enabled = $true
47+
48+
Invoke-Pester -Configuration $config
49+
} else {
50+
Write-Host "No Pester test files found."
51+
}

.github/workflows/scriptAnalyzer.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ on:
77
paths:
88
- "**/*.ps1"
99
- "**/*.psm1"
10+
- "**/*.psd1"
1011
push:
1112
paths:
1213
- "**/*.ps1"
1314
- "**/*.psm1"
15+
- "**/*.psd1"
1416

1517
permissions:
1618
contents: read # Needed to check out the code
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# YamlCreate.InstallerDetection Tests
2+
3+
This directory contains Pester tests for the YamlCreate.InstallerDetection PowerShell module.
4+
5+
## Overview
6+
7+
The test suite validates the functionality of the installer detection module, which provides functions to:
8+
- Parse PE file structures
9+
- Detect various installer types (ZIP, MSIX, MSI, WIX, Nullsoft, Inno, Burn)
10+
- Identify font files
11+
- Resolve installer types from file paths
12+
13+
## Running the Tests
14+
15+
### Prerequisites
16+
17+
- PowerShell 7.0 or later
18+
- Pester 5.x (included with PowerShell 7+)
19+
20+
### Run All Tests
21+
22+
From the module directory, run:
23+
24+
```powershell
25+
Invoke-Pester -Path ./YamlCreate.InstallerDetection.Tests.ps1
26+
```
27+
28+
### Run Tests with Detailed Output
29+
30+
For more detailed test output:
31+
32+
```powershell
33+
Invoke-Pester -Path ./YamlCreate.InstallerDetection.Tests.ps1 -Output Detailed
34+
```
35+
36+
### Run Tests with Code Coverage
37+
38+
To see code coverage metrics:
39+
40+
```powershell
41+
Invoke-Pester -Path ./YamlCreate.InstallerDetection.Tests.ps1 -CodeCoverage ./YamlCreate.InstallerDetection.psm1
42+
```
43+
44+
## Test Structure
45+
46+
The test suite is organized into the following sections:
47+
48+
### Module Tests
49+
- Module import validation
50+
- Exported functions verification
51+
52+
### Function Tests
53+
- **Get-OffsetBytes**: Tests for byte array extraction with various offsets and endianness
54+
- **Get-PESectionTable**: Tests for PE file parsing
55+
- **Test-IsZip**: Tests for ZIP file detection
56+
- **Test-IsMsix**: Tests for MSIX/APPX detection
57+
- **Test-IsMsi**: Tests for MSI installer detection
58+
- **Test-IsWix**: Tests for WIX installer detection
59+
- **Test-IsNullsoft**: Tests for Nullsoft installer detection
60+
- **Test-IsInno**: Tests for Inno Setup installer detection
61+
- **Test-IsBurn**: Tests for Burn installer detection
62+
- **Test-IsFont**: Tests for font file detection (TTF, OTF, TTC)
63+
- **Resolve-InstallerType**: Tests for the main installer type resolution function
64+
65+
## Known Limitations
66+
67+
Some tests are skipped due to complexity or external dependencies:
68+
69+
1. **ZIP Archive Tests**: Tests that require complete valid ZIP archives are skipped as they would need complex ZIP structure generation
70+
2. **PE File Tests**: Some PE-related tests are skipped when they would require reading non-existent files
71+
3. **External Dependencies**: The module relies on external commands (`Get-MSITable`, `Get-MSIProperty`, `Get-Win32ModuleResource`) that are stubbed in the test environment
72+
73+
## Test Coverage
74+
75+
Current test coverage includes:
76+
- 32 passing tests
77+
- 3 skipped tests (require complex setup)
78+
- Covers all 11 exported functions
79+
- Tests both positive and negative scenarios
80+
- Validates edge cases and error handling
81+
82+
## Contributing
83+
84+
When adding new functions to the module:
85+
1. Add corresponding tests to `YamlCreate.InstallerDetection.Tests.ps1`
86+
2. Follow the existing test structure (Describe → Context → It blocks)
87+
3. Use descriptive test names that explain what is being tested
88+
4. Include both positive and negative test cases
89+
5. Clean up any temporary files created during tests
90+
91+
## Additional Resources
92+
93+
- [Pester Documentation](https://pester.dev/)
94+
- [PowerShell Testing Best Practices](https://pester.dev/docs/usage/test-file-structure)

0 commit comments

Comments
 (0)