Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pester 5 migration #94

Open
wants to merge 42 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
2a8f89e
Add pester 5 changes
dan-hughes Jan 21, 2025
1bc7b71
Disable old tests
dan-hughes Jan 21, 2025
3c0e96d
Migrate .Common
dan-hughes Jan 21, 2025
c41f26a
Add to changelog
dan-hughes Jan 21, 2025
59bcefb
Add .OptionValueHelper tests
dan-hughes Jan 21, 2025
68a054b
DSC_xDhcpServerReservation Tests part 1
dan-hughes Jan 21, 2025
9b4c28e
Update changelog
dan-hughes Jan 21, 2025
582344f
Add dummy integration test
dan-hughes Jan 21, 2025
1cf9421
Remove Export-ModuleMember for Pester 5
dan-hughes Jan 21, 2025
5c43408
Fix mof
dan-hughes Jan 21, 2025
e0557d2
Revert resource AddressFamily changes
dan-hughes Jan 22, 2025
6884fd2
DSC_xDhcpServerReservation Part 2
dan-hughes Jan 22, 2025
a90750a
Disable warning on stub import
dan-hughes Jan 22, 2025
0992dda
DSC_DhcpPolicyOptionValue Part 1
dan-hughes Jan 22, 2025
3a9d332
DSC_DhcpPolicyOptionValue Part 2
dan-hughes Jan 22, 2025
c5021bd
Remove commented code and newlines
dan-hughes Jan 22, 2025
c2d42c7
DSC_DhcpReservedIPOptionValue tests
dan-hughes Jan 22, 2025
28b5cb2
Fix error condition tests
dan-hughes Jan 22, 2025
047349c
Replace $env:computerName with Get-ComputerName
dan-hughes Jan 24, 2025
ce70ca3
Add optionvalue tests
dan-hughes Jan 24, 2025
f40cfb9
Add ServerBinding tests
dan-hughes Jan 24, 2025
98e09ea
Update IPAddress creation
dan-hughes Jan 24, 2025
54d688c
Fix HQRM issue use of alias
dan-hughes Jan 26, 2025
b5ecfff
Remove old test data
dan-hughes Jan 26, 2025
95c9da7
Update variable name for consistency
dan-hughes Jan 26, 2025
dbec00b
DhcpServerExclusionRange tests
dan-hughes Jan 26, 2025
472e21e
Try and use ModuleFast
dan-hughes Jan 26, 2025
9b43704
Remove mock data
dan-hughes Jan 26, 2025
beb54e1
Use Get-ComputerName and fix uninitialized variable
dan-hughes Jan 26, 2025
64b0e87
Migrate xDhcpServerAuthorization
dan-hughes Jan 26, 2025
857ba57
Re-add mockdata
dan-hughes Jan 26, 2025
43160d9
xDhcpServerClass part 1
dan-hughes Jan 26, 2025
69cafb7
Fix No pipeline input error
dan-hughes Jan 26, 2025
416efdb
Fix typo
dan-hughes Jan 26, 2025
38c62a1
Migrate xDhcpServerClass
dan-hughes Jan 26, 2025
aadcd8f
Migrate xDhcpServerOptionDefinition
dan-hughes Jan 27, 2025
97dfeff
Remove commented code
dan-hughes Jan 27, 2025
f85c220
Update code coverage %
dan-hughes Jan 29, 2025
e3b5b35
Update changelog
dan-hughes Jan 29, 2025
99141ff
Add newline after }
dan-hughes Jan 29, 2025
ccc99cd
xDhcpServerScope Part 1
dan-hughes Jan 29, 2025
3a6425c
xDhcpServerScope part 2
dan-hughes Jan 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- `DhcpServerDsc`
- Migrate unit tests to Pester 5
- IPv6 preparation work
- Increased code coverage to >85% fixes [#60](https://github.com/dsccommunity/DhcpServerDsc/issues/60).

### Added

- Unit tests for `DhcpServerDsc.OptionValueHelper`
- Unit tests for `DSC_xDhcpServerReservation`

## [4.0.0] - 2025-01-20

### Changed
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
12 changes: 6 additions & 6 deletions Resolve-Dependency.psd1
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
@{
Gallery = 'PSGallery'
AllowPrerelease = $false
WithYAML = $true
Gallery = 'PSGallery'
AllowPrerelease = $false
WithYAML = $true

#UseModuleFast = $true
UseModuleFast = $true
#ModuleFastVersion = '0.1.2'
#ModuleFastBleedingEdge = $true

UsePSResourceGet = $true
UsePSResourceGet = $true
#PSResourceGetVersion = '1.0.1'

UsePowerShellGetCompatibilityModule = $true
UsePowerShellGetCompatibilityModule = $true
UsePowerShellGetCompatibilityModuleVersion = '3.0.23-beta23'
}
58 changes: 42 additions & 16 deletions build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ BuildWorkflow:
- package_module_nupkg

hqrmtest:
- DscResource_Tests_Stop_On_Fail
- Invoke_HQRM_Tests_Stop_On_Fail

test:
- Pester_Tests_Stop_On_Fail
Expand All @@ -69,29 +69,51 @@ BuildWorkflow:
####################################################

Pester:
OutputFormat: NUnitXML
Configuration:
Run:
Path:
- tests/Unit
Output:
Verbosity: Detailed
StackTraceVerbosity: Full
CIFormat: Auto
CodeCoverage:
CoveragePercentTarget: 85
OutputPath: CodeCoverage.xml
OutputEncoding: ascii
UseBreakpoints: false
TestResult:
OutputFormat: NUnitXML
OutputEncoding: ascii
ExcludeFromCodeCoverage:
- Modules/DscResource.Common
Script:
- tests/Unit
Tag:
CodeCoverageThreshold: 65
CodeCoverageOutputFile: CodeCoverage.xml
CodeCoverageOutputFileEncoding: ascii

CodeCoverage:
CodeCoverageMergedOutputFile: CodeCov_Merged.xml
CodeCoverageFilePattern: Codecov*.xml

DscTest:
ExcludeTag:
- "Common Tests - New Error-Level Script Analyzer Rules"
Tag:
ExcludeSourceFile:
- output
ExcludeModuleFile:
- Modules/DscResource.Common
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
# Must exclude built module file because it should not be tested like MOF-based resources
- DhcpServerDsc.psm1
MainGitBranch: main

ModuleBuildTasks:
Sampler:
Expand All @@ -100,6 +122,8 @@ ModuleBuildTasks:
- '*.ib.tasks'
DscResource.DocGenerator:
- 'Task.*'
DscResource.Test:
- 'Task.*'

TaskHeader: |
param($Path)
Expand All @@ -115,6 +139,8 @@ TaskHeader: |
GitHubConfig:
GitHubFilesToAdd:
- 'CHANGELOG.md'
ReleaseAssets:
- output/WikiContent.zip
GitHubConfigUserName: dscbot
GitHubConfigUserEmail: [email protected]
UpdateChangelogOnPrerelease: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function Get-TargetResource

if ($bindings.InterfaceAlias -inotcontains $InterfaceAlias)
{
$errorMessage = $script:localizedData.InterfaceAliasIsMissing -f $InterfaceAlias, $env:COMPUTERNAME
$errorMessage = $script:localizedData.InterfaceAliasIsMissing -f $InterfaceAlias, (Get-ComputerName)

New-ObjectNotFoundException -Message $errorMessage
}
Expand Down Expand Up @@ -149,5 +149,3 @@ function Test-TargetResource
return $false
}
}

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ function Get-TargetResource
# Check for DhcpServer module/role
Assert-Module -ModuleName 'DHCPServer'

$ScopeId = (Get-ValidIpAddress -IpString $ScopeId -AddressFamily $AddressFamily -ParameterName 'ScopeId').IPAddressToString
$IPStartRange = (Get-ValidIpAddress -IpString $IPStartRange -AddressFamily $AddressFamily -ParameterName 'StartRange').IPAddressToString
$IPEndRange = (Get-ValidIpAddress -IpString $IPEndRange -AddressFamily $AddressFamily -ParameterName 'EndRange').IPAddressToString
$ScopeId = Get-ValidIpAddress -IpString $ScopeId -AddressFamily $AddressFamily -ParameterName 'ScopeId'
$StartRange = Get-ValidIpAddress -IpString $IPStartRange -AddressFamily $AddressFamily -ParameterName 'StartRange'
$EndRange = Get-ValidIpAddress -IpString $IPEndRange -AddressFamily $AddressFamily -ParameterName 'EndRange'

# Check to ensure startRange is smaller than endRange
if ($IPEndRange.Address -lt $IPStartRange.Address)
if ($EndRange.Address -lt $StartRange.Address)
{
$errorMessage = $script:localizedData.InvalidStartAndEndRange

New-InvalidArgumentException -ArgumentName 'StartRange' -Message $errorMessage
New-ArgumentException -ArgumentName 'StartRange' -Message $errorMessage
}

# Retrieve exclusions for the scope
Expand All @@ -69,8 +69,8 @@ function Get-TargetResource
[System.Array] $dhcpExclusionRange = Get-DhcpServerv4ExclusionRange -ScopeId $ScopeId -ErrorAction 'SilentlyContinue'

$testExclusionRange = $dhcpExclusionRange |
Where-Object -FIlterScript {
$_.StartRange -eq $IPStartRange -and $_.EndRange -eq $IPEndRange
Where-Object -FilterScript {
$_.StartRange -eq $StartRange -and $_.EndRange -eq $EndRange
}

$ipStart = $testExclusionRange.StartRange.IPAddressToString
Expand Down Expand Up @@ -223,7 +223,7 @@ function Test-TargetResource
{
$errorMessage = $script:localizedData.InvalidStartAndEndRange

New-InvalidArgumentException -ArgumentName 'StartRange' -Message $errorMessage
New-ArgumentException -ArgumentName 'StartRange' -Message $errorMessage
}

# Retrieve exclusions for the scope
Expand All @@ -233,13 +233,13 @@ function Test-TargetResource

$testExclusionRange = $dhcpExclusionRange |
Where-Object -FilterScript {
$_.StartRange -eq $IPStartRange -and $_.EndRange -eq $IPEndRange
$_.StartRange -eq $validStartRange -and $_.EndRange -eq $validEndRange
}

$ipStart = $testExclusionRange.StartRange.IPAddressToString
$ipEnd = $testExclusionRange.EndRange.IPAddressToString

if ($Ensure -ieq 'Present')
if ($Ensure -eq 'Present')
{
if ($testExclusionRange)
{
Expand All @@ -251,12 +251,12 @@ function Test-TargetResource
else
{
Write-Verbose -Message ($script:localizedData.ExclusionNotFound -f $IPStartRange, $IPEndRange)
Write-Verbose -Message ($script:localizedData.NotInDesiredState -f $ScopeId, $Ensure, "Absent")
Write-Verbose -Message ($script:localizedData.NotInDesiredState -f $ScopeId, $Ensure, 'Absent')

return $false
}
}
elseif ($Ensure -ieq 'Absent')
elseif ($Ensure -eq 'Absent')
{
if (-not $testExclusionRange)
{
Expand All @@ -268,11 +268,9 @@ function Test-TargetResource
else
{
Write-Verbose -Message ($script:localizedData.FoundExclusion -f $ScopeId, $ipStart, $ipEnd)
Write-Verbose -Message ($script:localizedData.NotInDesiredState -f $ScopeId, $Ensure, "Present")
Write-Verbose -Message ($script:localizedData.NotInDesiredState -f $ScopeId, $Ensure, 'Present')

return $false
}
}
}

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function Get-TargetResource
[Parameter()]
[ValidateNotNullOrEmpty()]
[System.String]
$DnsName = (Get-Hostname),
$DnsName = (Get-ComputerName),

[Parameter()]
[ValidateNotNullOrEmpty()]
Expand All @@ -34,7 +34,7 @@ function Get-TargetResource
)

Write-Verbose -Message (
$script:localizedData.GetServerAuthorizationMessage -f $ScopeId
$script:localizedData.GetServerAuthorizationMessage -f $DnsName
)

Assert-Module -ModuleName 'DHCPServer'
Expand Down Expand Up @@ -84,7 +84,7 @@ function Set-TargetResource
[Parameter()]
[ValidateNotNullOrEmpty()]
[System.String]
$DnsName = (Get-Hostname),
$DnsName = (Get-ComputerName),

[Parameter()]
[ValidateNotNullOrEmpty()]
Expand All @@ -93,7 +93,7 @@ function Set-TargetResource
)

Write-Verbose -Message (
$script:localizedData.SetServerAuthorizationMessage -f $ScopeId
$script:localizedData.SetServerAuthorizationMessage -f $DnsName
)

Assert-Module -ModuleName 'DHCPServer'
Expand All @@ -110,9 +110,14 @@ function Set-TargetResource
{
Write-Verbose ($script:localizedData.UnauthorizingServer -f $DnsName, $IPAddress)

Get-DhcpServerInDC | Where-Object -FilterScript {
$dhcpServers = Get-DhcpServerInDC | Where-Object -FilterScript {
($_.DnsName -eq $DnsName) -and ($_.IPAddress -eq $IPAddress)
} | Remove-DhcpServerInDc
}

foreach ($dhcpServer in $dhcpServers)
{
Remove-DhcpServerInDc -DnsName $dhcpServer.DnsName -IPAddress $dhcpServer.IPAddress
}
}
}

Expand All @@ -135,7 +140,7 @@ function Test-TargetResource
[Parameter()]
[ValidateNotNullOrEmpty()]
[System.String]
$DnsName = (Get-Hostname),
$DnsName = (Get-ComputerName),

[Parameter()]
[ValidateNotNullOrEmpty()]
Expand All @@ -144,7 +149,7 @@ function Test-TargetResource
)

Write-Verbose -Message (
$script:localizedData.TestServerAuthorizationMessage -f $ScopeId
$script:localizedData.TestServerAuthorizationMessage -f $DnsName
)

$targetResource = Get-TargetResource @PSBoundParameters
Expand Down Expand Up @@ -198,7 +203,7 @@ function Get-IPv4Address
Where-Object -FilterScript {
$_.IPEnabled -eq 'True' -and $_.IPAddress -notmatch ':'
} |
Select-Object -ExpandProperty 'IPAddress'
Select-Object -ExpandProperty 'IPAddress'
} #end process
} #end function Get-IPv4Address

Expand All @@ -224,5 +229,3 @@ function Get-Hostname
}
} #end process
} #end function Get-Hostname

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function Set-TargetResource
$scopeIDMessage = $script:localizedData.SettingClassIDMessage -f $Name
Write-Verbose -Message $scopeIDMessage

set-DhcpServerv4Class -Name $Name -Type $Type -Data $AsciiData -Description $Description
Set-DhcpServerv4Class -Name $Name -Type $Type -Data $AsciiData -Description $Description
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,5 +402,3 @@ function Update-ResourceProperties
}

#endregion

Export-ModuleMember -Function *-TargetResource
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ function Set-TargetResource
SubnetMask = $SubnetMask
AddressFamily = $AddressFamily
}

Assert-ScopeParameter @ipAddressesAssertionParameters

#endregion Input Validation
Expand Down Expand Up @@ -712,5 +713,3 @@ function Update-ResourceProperties
}
} # else !dhcpscope
}

Export-ModuleMember -Function *-TargetResource
Loading