Skip to content

Commit c6073f0

Browse files
authored
Migrate Tests to Pester 5 (#296)
1 parent 6e3b4f4 commit c6073f0

51 files changed

Lines changed: 14564 additions & 13206 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.vscode/settings.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@
3636
"keepachangelog",
3737
"notin",
3838
"pscmdlet",
39-
"steppable"
39+
"steppable",
40+
"vhdx",
41+
"cdrom",
42+
"ntfs",
43+
"PHYSICALDRIVE"
4044
],
4145
"cSpell.ignorePaths": [
4246
".git"

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
55

66
## [Unreleased]
77

8+
### Changed
9+
10+
- Unit tests converted to Pester 5. Fixes [#265](https://github.com/dsccommunity/StorageDsc/issues/265).
11+
- Split bundled modules into buildable modules and separate files.
12+
13+
### Removed
14+
15+
- `CommonTestHelper`
16+
- Use versions from `DscResource.Test`
17+
- Get-InvalidArgumentRecord
18+
- Get-InvalidOperationRecord
19+
820
### Fixed
921

1022
- Azure DevOps Build Pipeline:

RequiredModules.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
InvokeBuild = 'latest'
1111
PSScriptAnalyzer = 'latest'
12-
Pester = '4.10.1'
12+
Pester = 'latest'
1313
Plaster = 'latest'
1414
ModuleBuilder = 'latest'
1515
ChangelogManagement = 'latest'

azure-pipelines.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
trigger:
22
branches:
33
include:
4-
- main
4+
- main
55
paths:
66
include:
7-
- source/*
7+
- source/*
88
tags:
99
include:
10-
- "v*"
10+
- 'v*'
1111
exclude:
12-
- "*-*"
12+
- '*-*'
1313

1414
variables:
1515
buildFolderName: output
@@ -91,8 +91,6 @@ stages:
9191
displayName: 'Unit'
9292
strategy:
9393
matrix:
94-
Windows Server 2019:
95-
vmImage: windows-2019
9694
Windows Server 2022:
9795
vmImage: windows-2022
9896
Windows Server 2025:

build.yaml

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ BuildWorkflow:
2626
- package_module_nupkg
2727

2828
hqrmtest:
29-
- DscResource_Tests_Stop_On_Fail
29+
- Invoke_HQRM_Tests_Stop_On_Fail
3030

3131
test:
3232
- Pester_Tests_Stop_On_Fail
@@ -40,7 +40,6 @@ BuildWorkflow:
4040
- publish_module_to_gallery
4141
- Publish_Release_To_GitHub
4242
- Publish_GitHub_Wiki_Content
43-
- Create_ChangeLog_GitHub_PR
4443

4544
####################################################
4645
# ModuleBuilder Configuration #
@@ -88,15 +87,6 @@ NestedModule:
8887
# Pester Configuration (Sampler) #
8988
####################################################
9089
Pester:
91-
# Pester 4 configuration
92-
Script:
93-
- tests/Unit
94-
ExcludeTag:
95-
Tag:
96-
CodeCoverageOutputFileEncoding: ascii
97-
CodeCoverageThreshold: 80
98-
99-
# Pester 5 configuration
10090
Configuration:
10191
Run:
10292
Path:
@@ -106,7 +96,7 @@ Pester:
10696
StackTraceVerbosity: Full
10797
CIFormat: Auto
10898
CodeCoverage:
109-
CoveragePercentTarget: 80
99+
CoveragePercentTarget: 85
110100
OutputEncoding: ascii
111101
UseBreakpoints: false
112102
TestResult:
@@ -130,14 +120,27 @@ CodeCoverage:
130120
# Pester Configuration (DscResource.Test) #
131121
####################################################
132122
DscTest:
133-
OutputFormat: NUnitXML
134-
ExcludeTag:
135-
- 'Common Tests - New Error-Level Script Analyzer Rules'
136-
ExcludeSourceFile:
137-
- output
138-
ExcludeModuleFile:
139-
- Modules/DscResource.Common
140-
MainGitBranch: main
123+
Pester:
124+
Configuration:
125+
Filter:
126+
ExcludeTag:
127+
- "Common Tests - New Error-Level Script Analyzer Rules"
128+
Output:
129+
Verbosity: Detailed
130+
CIFormat: Auto
131+
TestResult:
132+
Enabled: true
133+
OutputFormat: NUnitXML
134+
OutputEncoding: ascii
135+
OutputPath: ./output/testResults/NUnitXml_HQRM_Tests.xml
136+
Script:
137+
ExcludeSourceFile:
138+
- output
139+
ExcludeModuleFile:
140+
- Modules/DscResource.Common
141+
# Must exclude built module file because it should not be tested like MOF-based resources
142+
- StorageDsc.psm1
143+
MainGitBranch: main
141144

142145
####################################################
143146
# PSDepend Configuration #

source/Build.psd1

Lines changed: 0 additions & 5 deletions
This file was deleted.

source/DSCResources/DSC_Disk/DSC_Disk.psm1

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ function Set-TargetResource
372372
# Check if existing partition already has file system on it
373373
if ($null -eq $assignedPartition)
374374
{
375-
# There is no partiton with this drive letter
375+
# There is no partition with this drive letter
376376
Write-Verbose -Message ( @(
377377
"$($MyInvocation.MyCommand): "
378378
$($script:localizedData.DriveNotFoundOnPartitionMessage `
@@ -631,11 +631,12 @@ function Set-TargetResource
631631

632632
<#
633633
After creating the partition it can take a few seconds for it to become writeable
634-
Wait for up to 30 seconds for the parition to become writeable
634+
Wait for up to 30 seconds for the partition to become writeable
635635
#>
636636
$timeAtStart = Get-Date
637-
$minimumTimeToWait = $timeAtStart + (New-Timespan -Second 3)
638-
$maximumTimeToWait = $timeAtStart + (New-Timespan -Second 30)
637+
$minimumTimeToWait = $timeAtStart + (New-TimeSpan -Second 3)
638+
$maximumTimeToWait = $timeAtStart + (New-TimeSpan -Second 30)
639+
$partitionstate = $null
639640

640641
while (($partitionstate.IsReadOnly -and (Get-Date) -lt $maximumTimeToWait) `
641642
-or ((Get-Date) -lt $minimumTimeToWait))
@@ -657,7 +658,7 @@ function Set-TargetResource
657658
{
658659
# The partition is still readonly - throw an exception
659660
New-InvalidOperationException `
660-
-Message ($script:localizedData.NewParitionIsReadOnlyError `
661+
-Message ($script:localizedData.NewPartitionIsReadOnlyError `
661662
-f $DiskIdType, $DiskId, $partition.PartitionNumber)
662663
} # if
663664

@@ -709,7 +710,7 @@ function Set-TargetResource
709710

710711
if ($Size -gt $supportedSize.SizeMax)
711712
{
712-
New-InvalidArgumentException -Message ( @(
713+
New-ArgumentException -Message ( @(
713714
"$($MyInvocation.MyCommand): "
714715
$($script:localizedData.FreeSpaceViolationError `
715716
-f $DriveLetter, $assignedPartition.Size, $Size, $supportedSize.SizeMax)
@@ -837,7 +838,7 @@ function Set-TargetResource
837838
# The volume should have a label assigned
838839
if ($volume.FileSystemLabel -ne $FSLabel)
839840
{
840-
# The volume lable needs to be changed because it is different.
841+
# The volume label needs to be changed because it is different.
841842
Write-Verbose -Message ( @(
842843
"$($MyInvocation.MyCommand): "
843844
$($script:localizedData.ChangingVolumeLabelMessage `
@@ -891,7 +892,7 @@ function Set-TargetResource
891892

892893
<#
893894
.SYNOPSIS
894-
Tests if the disk is initialized, the partion exists and the drive letter is assigned.
895+
Tests if the disk is initialized, the partition exists and the drive letter is assigned.
895896
896897
.PARAMETER DriveLetter
897898
Specifies the preferred letter to assign to the disk volume.
@@ -1074,7 +1075,7 @@ function Test-TargetResource
10741075
If the difference in size between the supported partition size
10751076
and the current partition size is less than 1MB then set the
10761077
desired partition size to the current size. This will prevent
1077-
any size difference less than 1MB from trying to contiuously
1078+
any size difference less than 1MB from trying to continuously
10781079
resize. See https://github.com/dsccommunity/StorageDsc/issues/181
10791080
#>
10801081
if (($supportedSize.SizeMax - $partition.Size) -lt 1MB)
@@ -1114,7 +1115,7 @@ function Test-TargetResource
11141115
https://learn.microsoft.com/en-us/windows-hardware/drivers/storage/createpartition-msft-disk
11151116
for more information. But to some it up, what the user enters and what the New-Partition
11161117
cmdlet is able to allocate can be different in bytes. So to keep idempotence, we only
1117-
return false when they arent the same in GB. Also if the volume already is formatted as
1118+
return false when they are not the same in GB. Also if the volume already is formatted as
11181119
a ReFS, there is no point in returning false for size mismatches since they can't be
11191120
resized with resize-partition.
11201121
#>

source/DSCResources/DSC_Disk/en-US/DSC_Disk.strings.psd1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ConvertFrom-StringData @'
1+
ConvertFrom-StringData @'
22
GettingDiskMessage = Getting disk with {0} '{1}' status for drive letter '{2}'.
33
SettingDiskMessage = Setting disk with {0} '{1}' status for drive letter '{2}'.
44
SetDiskOnlineMessage = Setting disk with {0} '{1}' online.
@@ -33,7 +33,7 @@
3333
MatchingPartitionFoundMessage = Disk with {0} '{1}' already contains partitions, and partition '{2}' matches required size.
3434
DriveNotFoundOnPartitionMessage = Disk with {0} '{1}' does not contain a partition assigned to drive letter '{2}'.
3535
ClearingDiskMessage = Clearing disk with {0} '{1}' of all existing partitions and volumes.
36-
NewParitionIsReadOnlyError = New partition '{2}' on disk with {0} '{1}' did not become writable in the expected time.
36+
NewPartitionIsReadOnlyError = New partition '{2}' on disk with {0} '{1}' did not become writable in the expected time.
3737
VolumeFormatInProgressMessage = Switch AllowDestructive is specified. Attempting to format volume on {0} with '{2}', was '{1}'.
3838
SizeMismatchCorrectionMessage = Switch AllowDestructive is specified. Attempting to resize partition {0} from {1} to {2}.
3939
FreeSpaceViolationError = Attempted to resize partition {0} from {1} to {2} while maximum allowed size was {3}.

source/DSCResources/DSC_DiskAccessPath/en-US/DSC_DiskAccessPath.strings.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ConvertFrom-StringData @'
1+
ConvertFrom-StringData @'
22
GettingDiskMessage = Getting disk with {0} '{1}' status for access path '{2}'.
33
SettingDiskMessage = Setting disk with {0} '{1}' status for access path '{2}'.
44
SetDiskOnlineMessage = Setting disk with {0} '{1}' online.

source/DSCResources/DSC_MountImage/DSC_MountImage.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ function Test-ParameterValid
461461
if ($PSBoundParameters.ContainsKey('DriveLetter'))
462462
{
463463
# Test the Drive Letter to ensure it is valid
464-
$normalizedDriveLetter = Assert-DriveLetterValid -DriveLetter $DriveLetter
464+
Assert-DriveLetterValid -DriveLetter $DriveLetter
465465
}
466466
else
467467
{

0 commit comments

Comments
 (0)