Skip to content

Commit c6847b9

Browse files
authored
Merge pull request AutomatedLab#1770 from dkettman/customRolePesterTests
(Fixes AutomatedLab#1764) Updated Invoke-LabPester.ps1 to now check the CustomRole directories
2 parents ac5e1a1 + c6411fa commit c6847b9

File tree

4 files changed

+29
-18
lines changed

4 files changed

+29
-18
lines changed

AutomatedLabTest/functions/Invoke-LabPester.ps1

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
function Invoke-LabPester
2-
{
1+
function Invoke-LabPester {
32
[CmdletBinding(DefaultParameterSetName = 'ByLab')]
43
param
54
(
@@ -21,37 +20,39 @@
2120
$OutputFile
2221
)
2322

24-
process
25-
{
26-
if (-not $Lab)
27-
{
23+
process {
24+
if (-not $Lab) {
2825
$Lab = Import-Lab -Name $LabName -ErrorAction Stop -NoDisplay -NoValidation -PassThru
2926
}
3027

3128
$global:pesterLab = $Lab # No parameters in Pester v5 yet
3229
$configuration = [PesterConfiguration]::Default
33-
$configuration.Run.Path = Join-Path -Path $PSCmdlet.MyInvocation.MyCommand.Module.ModuleBase -ChildPath 'tests'
30+
$config_paths = @() # Setup the array to pass to $Configuration.Run.Path
31+
$config_paths += Join-Path -Path $PSCmdlet.MyInvocation.MyCommand.Module.ModuleBase -ChildPath 'tests' # This is for the built-in Roles
3432
$configuration.Run.PassThru = $PassThru.IsPresent
3533
[string[]]$tags = 'General'
3634

37-
if ($Lab.Machines.Roles.Name)
38-
{
35+
if ($Lab.Machines.Roles.Name) {
3936
$tags += $Lab.Machines.Roles.Name
4037
}
41-
if ($Lab.Machines.PostInstallationActivity | Where-Object IsCustomRole)
42-
{
38+
if ($Lab.Machines.PostInstallationActivity | Where-Object IsCustomRole) {
4339
$tags += ($Lab.Machines.PostInstallationActivity | Where-Object IsCustomRole).RoleName
40+
foreach ( $role in (($Lab.Machines.PostInstallationActivity | Where-Object IsCustomRole).RoleName)) {
41+
$config_paths += Join-Path -Path $global:LabSources\CustomRoles -ChildPath $role
42+
}
4443
}
45-
if ($Lab.Machines.PreInstallationActivity | Where-Object IsCustomRole)
46-
{
44+
if ($Lab.Machines.PreInstallationActivity | Where-Object IsCustomRole) {
4745
$tags += ($Lab.Machines.PreInstallationActivity | Where-Object IsCustomRole).RoleName
46+
foreach ( $role in (($Lab.Machines.PreInstallationActivity | Where-Object IsCustomRole).RoleName)) {
47+
$config_paths += Join-Path -Path $global:LabSources\CustomRoles -ChildPath $role
48+
}
4849
}
49-
50+
$configuration.Run.Path = $config_paths | Sort-Object -Unique
5051
$configuration.Filter.Tag = $tags
5152
$configuration.Should.ErrorAction = 'Continue'
5253
$configuration.TestResult.Enabled = $true
53-
if ($OutputFile)
54-
{
54+
55+
if ($OutputFile) {
5556
$configuration.TestResult.OutputPath = $OutputFile
5657
}
5758
$configuration.Output.Verbosity = $Show

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Changelog
22

3-
## Unreleased (yyyy-MM-dd)
3+
## Unreleased (2025-08-21)
4+
5+
- Updated `Invoke-LabPester` to scan the `$global:LabSources\CustomRoles` directory for Pester tests (#1764)
46

57
## 5.59.0 (2025-08-18)
68

Help/AutomatedLabTest/en-us/Invoke-LabPester.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ Invoke-LabPester -LabName <String> [-Show <Object>] [-PassThru] [-OutputFile <St
2323
```
2424

2525
## DESCRIPTION
26-
Invoke all role-specific pester tests for a lab
26+
Invoke all role-specific pester tests for a lab. This includes any tests that exist in CustomRoles. Use
27+
`New-LabPesterTest` to create the Pester test stub in your Custom Role folder.
2728

2829
## EXAMPLES
2930

Help/Wiki/Advanced/customroles.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ As AutomatedLab copies the whole folder to the machine the role is assigned to,
7979
& $PSScriptRoot\Customizations.ps1
8080
```
8181

82+
### Custom Role Tests
83+
Pester tests are now available for Custom Roles! Use `New-LabPesterTest` to create the stub test harness like this:
84+
85+
```PowerShell
86+
New-LabPesterTest -Role MyCustomRole -IsCustomRole -Path $global:LabSources\CustomRoles\MyCustomRole
87+
```
88+
8289
The same pattern can be used for HostStart and HostEnd as well. You do not have to put all the logic in just one file.
8390

8491
### Demo Roles

0 commit comments

Comments
 (0)