Skip to content

Commit

Permalink
Migrate to Pester 5 (#434)
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-hughes authored Sep 30, 2024
1 parent fb177d6 commit 62ba944
Show file tree
Hide file tree
Showing 56 changed files with 15,364 additions and 11,729 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@
"pester.pesterModulePath": "./output/RequiredModules/Pester",
"powershell.pester.codeLens": true,
"pester.suppressCodeLensNotice": true,
"yaml.format.singleQuote": true,
}
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- `VirtualMemory` fix incorrect variable name
- `SmbServerConfiguration` remove errant argument

### Changed

- Converted tests to Pester 5
- Rename Delete-ADSIObject to Delete-ADSIObject to satisfy HQRM

### Removed

- Removed `Get-InvalidOperationRecord` to use version provided by `DscResource.Test`

## [9.2.0] - 2024-09-30

### Added
Expand Down
2 changes: 1 addition & 1 deletion RequiredModules.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

InvokeBuild = 'latest'
PSScriptAnalyzer = 'latest'
Pester = '4.10.1'
Pester = 'latest'
Plaster = 'latest'
ModuleBuilder = 'latest'
ChangelogManagement = 'latest'
Expand Down
53 changes: 28 additions & 25 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ BuildWorkflow:
- package_module_nupkg

hqrmtest:
- DscResource_Tests_Stop_On_Fail
- Invoke_HQRM_Tests_Stop_On_Fail

test:
- Pester_Tests_Stop_On_Fail
- Convert_Pester_Coverage
- Pester_If_Code_Coverage_Under_Threshold

publish:
- publish_module_to_gallery
- Publish_Release_To_GitHub
- Publish_Module_To_gallery
- Publish_GitHub_Wiki_Content
- Create_ChangeLog_GitHub_PR

####################################################
# ModuleBuilder Configuration #
Expand Down Expand Up @@ -91,16 +91,6 @@ NestedModule:
# Pester Configuration (Sampler) #
####################################################
Pester:
# Pester 4 configuration
Script:
- tests/Unit
ExcludeTag:
Tag:
CodeCoverageOutputFile: JaCoCo_coverage.xml
CodeCoverageOutputFileEncoding: ascii
CodeCoverageThreshold: 80

# Pester 5 configuration
Configuration:
Run:
Path:
Expand All @@ -110,7 +100,7 @@ Pester:
StackTraceVerbosity: Full
CIFormat: Auto
CodeCoverage:
CoveragePercentTarget: 80
CoveragePercentTarget: 85
OutputPath: JaCoCo_coverage.xml
OutputEncoding: ascii
UseBreakpoints: false
Expand All @@ -125,15 +115,28 @@ Pester:
# Pester Configuration (DscResource.Test) #
####################################################
DscTest:
OutputFormat: NUnitXML
ExcludeTag:
- 'Common Tests - New Error-Level Script Analyzer Rules'
ExcludeSourceFile:
- output
ExcludeModuleFile:
- Modules/DscResource.Common
- Modules/DscResource.Base
MainGitBranch: main
Pester:
Configuration:
Filter:
ExcludeTag:
- "Common Tests - New Error-Level Script Analyzer Rules"
Output:
Verbosity: Detailed
CIFormat: Auto
TestResult:
Enabled: true
OutputFormat: NUnitXML
OutputEncoding: ascii
OutputPath: ./output/testResults/NUnitXml_HQRM_Tests.xml
Script:
ExcludeSourceFile:
- output
ExcludeModuleFile:
- Modules/DscResource.Common
- Modules/DscResource.Base
# Must exclude built module file because it should not be tested like MOF-based resources
- ComputerManagementDsc.psm1
MainGitBranch: main

####################################################
# PSDepend Configuration #
Expand Down Expand Up @@ -180,5 +183,5 @@ DscResource.DocGenerator:
Type: CompositeResource
Category: Resources
Generate_Wiki_Sidebar:
Debug: false
AlwaysOverwrite: true
Debug: false
AlwaysOverwrite: true
11 changes: 4 additions & 7 deletions source/DSCResources/DSC_Computer/DSC_Computer.psm1
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', '', Scope = 'Function')]
param
(
)
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', 'DSCMachineStatus', Justification = 'GlobalDsc Variable can be ignored')]
param ()

$modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules'

Expand Down Expand Up @@ -268,7 +267,7 @@ function Set-TargetResource

if ($computerObject)
{
Delete-ADSIObject -Path $computerObject.Path -Credential $Credential
Remove-ADSIObject -Path $computerObject.Path -Credential $Credential
Write-Verbose -Message ($script:localizedData.DeletedExistingComputerObject -f $Name, $computerObject.Path)
}

Expand Down Expand Up @@ -755,7 +754,7 @@ function Get-ADSIComputer
.PARAMETER Credential
Credential to authenticate to the domain.
#>
function Delete-ADSIObject
function Remove-ADSIObject
{
[CmdletBinding()]
param
Expand Down Expand Up @@ -877,5 +876,3 @@ function Assert-ResourceProperty
-ArgumentName 'Credential'
}
}

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', '', Scope = 'Function')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', 'DSCMachineStatus', Justification = 'GlobalDsc Variable can be ignored')]
param ()

$modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules'

# Import the ComputerManagementDsc Common Modules
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidGlobalVars", "", Scope = "Function")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', 'DSCMachineStatus', Justification = 'GlobalDsc Variable can be ignored')]
param
(
)
Expand Down Expand Up @@ -239,5 +240,3 @@ function Get-DomainName
$computerSystem.Domain
}
} # function Get-DomainName

Export-ModuleMember -Function *-TargetResource
3 changes: 1 addition & 2 deletions source/DSCResources/DSC_PendingReboot/DSC_PendingReboot.psm1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidGlobalVars", "", Scope = "Function")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', 'DSCMachineStatus', Justification = 'GlobalDsc Variable can be ignored')]
param ()

$modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules'
Expand Down Expand Up @@ -383,5 +384,3 @@ function Get-PendingRebootState

return $pendingRebootState
}

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@{
@{
RebootTriggers = @(
@{
Name = 'ComponentBasedServicing'
Expand Down
2 changes: 0 additions & 2 deletions source/DSCResources/DSC_PowerPlan/DSC_PowerPlan.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -154,5 +154,3 @@ function Test-TargetResource

return $getTargetResourceResult.IsActive
}

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,3 @@ function Test-TargetResource
return $false
}
}

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
Expand Up @@ -180,5 +180,3 @@ function Set-TargetResource
Set-ItemProperty -Path $script:winStationsRegistryKey -Name "UserAuthentication" -Value $UserAuthenticationRegistry
}
}

Export-ModuleMember -Function *-TargetResource
5 changes: 4 additions & 1 deletion source/DSCResources/DSC_ScheduledTask/DSC_ScheduledTask.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ function Set-TargetResource

$action = New-ScheduledTaskAction @actionParameters

$scheduledTaskArguments += @{
$scheduledTaskArguments = @{
Action = $action
}

Expand Down Expand Up @@ -715,6 +715,9 @@ function Set-TargetResource
-ErrorRecord $_
}

# Add to please strict mode
$repetition = $null

if ($RepeatInterval -gt [System.TimeSpan]::Parse('0:0:0'))
{
# A repetition pattern is required so create it and attach it to the trigger object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function Get-TargetResource
$IsSingleInstance
)

Write-Verbose -Message ($script:localizedData.GetTargetResourceMessage -f $Name)
Write-Verbose -Message ($script:localizedData.GetTargetResourceMessage)

$smbReturn = @{}
$smbServer = Get-SmbServerConfiguration -ErrorAction 'SilentlyContinue'
Expand Down Expand Up @@ -704,5 +704,3 @@ function Test-TargetResource

return $resourceCompliant
}

Export-ModuleMember -Function *-TargetResource
6 changes: 4 additions & 2 deletions source/DSCResources/DSC_SystemLocale/DSC_SystemLocale.psm1
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', '', Scope = 'Function')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', 'DSCMachineStatus', Justification = 'GlobalDsc Variable can be ignored')]
param ()

$modulePath = Join-Path -Path (Split-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -Parent) -ChildPath 'Modules'

# Import the ComputerManagementDsc Common Modules
Expand Down Expand Up @@ -187,5 +191,3 @@ function Test-SystemLocaleValue

return ($SystemLocale -in $validCultures)
}

Export-ModuleMember -Function *-TargetResource
2 changes: 0 additions & 2 deletions source/DSCResources/DSC_TimeZone/DSC_TimeZone.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,3 @@ function Test-TargetResource

return Test-TimeZoneId -TimeZoneId $TimeZone
}

Export-ModuleMember -Function *-TargetResource
Loading

0 comments on commit 62ba944

Please sign in to comment.