This repository was archived by the owner on Jul 16, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResolve-PSModuleVersion.Helpers.Tests.ps1
More file actions
190 lines (175 loc) · 8.06 KB
/
Copy pathResolve-PSModuleVersion.Helpers.Tests.ps1
File metadata and controls
190 lines (175 loc) · 8.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#Requires -Modules @{ ModuleName = 'Pester'; ModuleVersion = '5.0' }
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '',
Justification = 'Variables are used across Pester BeforeAll/It blocks.')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', '',
Justification = 'Parameters in LogGroup mock are required by the caller signature.')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSProvideCommentHelp', '',
Justification = 'LogGroup is a test helper mock, not a public function.')]
param()
# Load test data at script scope so it is available during Pester discovery (-ForEach)
$TestData = Import-PowerShellDataFile -Path "$PSScriptRoot/Resolve-PSModuleVersion.Helpers.Tests.Data.psd1"
BeforeAll {
# Install PSSemVer for version handling
if (-not (Get-Module -ListAvailable -Name PSSemVer)) {
Install-PSResource -Name PSSemVer -Repository PSGallery -TrustRepository -Scope CurrentUser
}
Import-Module -Name PSSemVer -Force
# Mock LogGroup so module functions execute their blocks without console decoration
function LogGroup {
param([string]$Name, [scriptblock]$ScriptBlock)
& $ScriptBlock
}
# Import the module under test
Import-Module -Name "$PSScriptRoot/../scripts/Resolve-PSModuleVersion.Helpers.psm1" -Force
}
Describe 'Resolve-ReleaseDecision' {
BeforeAll {
$baseConfig = [PSCustomObject]@{
AutoPatching = $false
IncrementalPrerelease = $false
DatePrereleaseFormat = ''
VersionPrefix = 'v'
ReleaseType = 'Release'
IgnoreLabels = @('skip-release')
MajorLabels = @('major')
MinorLabels = @('minor')
PatchLabels = @('patch')
}
}
Context '<Name>' -ForEach $TestData.ReleaseDecision {
BeforeAll {
$config = [PSCustomObject]@{
AutoPatching = $AutoPatching
IncrementalPrerelease = $baseConfig.IncrementalPrerelease
DatePrereleaseFormat = $baseConfig.DatePrereleaseFormat
VersionPrefix = $baseConfig.VersionPrefix
ReleaseType = $ReleaseType
IgnoreLabels = $baseConfig.IgnoreLabels
MajorLabels = $baseConfig.MajorLabels
MinorLabels = $baseConfig.MinorLabels
PatchLabels = $baseConfig.PatchLabels
}
$pullRequest = [PSCustomObject]@{
HeadRef = $HeadRef
Labels = $Labels
}
$result = Resolve-ReleaseDecision -Configuration $config -PullRequest $pullRequest
}
It 'ShouldPublish is <Expected.ShouldPublish>' {
$result.ShouldPublish | Should -Be $Expected.ShouldPublish
}
It 'CreateRelease is <Expected.CreateRelease>' {
$result.CreateRelease | Should -Be $Expected.CreateRelease
}
It 'CreatePrerelease is <Expected.CreatePrerelease>' {
$result.CreatePrerelease | Should -Be $Expected.CreatePrerelease
}
It 'MajorRelease is <Expected.MajorRelease>' {
$result.MajorRelease | Should -Be $Expected.MajorRelease
}
It 'MinorRelease is <Expected.MinorRelease>' {
$result.MinorRelease | Should -Be $Expected.MinorRelease
}
It 'PatchRelease is <Expected.PatchRelease>' {
$result.PatchRelease | Should -Be $Expected.PatchRelease
}
It 'HasVersionBump is <Expected.HasVersionBump>' {
$result.HasVersionBump | Should -Be $Expected.HasVersionBump
}
It 'PrereleaseName is <Expected.PrereleaseName>' {
$result.PrereleaseName | Should -Be $Expected.PrereleaseName
}
}
}
Describe 'Get-NextModuleVersion' {
BeforeAll {
Mock -CommandName Find-PSResource -ModuleName 'Resolve-PSModuleVersion.Helpers' -MockWith { @() }
$emptyReleases = @([PSCustomObject]@{ tagName = 'v0.0.0'; isLatest = $false; isPrerelease = $false })
}
Context '<Name>' -ForEach $TestData.NextModuleVersion {
BeforeAll {
$config = [PSCustomObject]@{
AutoPatching = $false
IncrementalPrerelease = $IncrementalPrerelease
DatePrereleaseFormat = $DatePrereleaseFormat
VersionPrefix = $VersionPrefix
ReleaseType = 'Release'
IgnoreLabels = @()
MajorLabels = @('major')
MinorLabels = @('minor')
PatchLabels = @('patch')
}
$decisionObj = [PSCustomObject]$Decision
$latestVer = New-PSSemVer -Version $LatestVersion
$result = Get-NextModuleVersion -LatestVersion $latestVer -Decision $decisionObj `
-Configuration $config -ModuleName 'TestModule' -Releases $emptyReleases
}
It 'Version is <ExpectedVersion>' {
"$($result.Major).$($result.Minor).$($result.Patch)" | Should -Be $ExpectedVersion
}
It 'Prerelease is <ExpectedPrerelease>' {
if ([string]::IsNullOrEmpty($ExpectedPrerelease)) {
$result.Prerelease | Should -BeNullOrEmpty
} else {
$result.Prerelease | Should -Be $ExpectedPrerelease
}
}
It 'Prefix is <ExpectedPrefix>' {
$result.Prefix | Should -Be $ExpectedPrefix
}
}
}
Describe 'End-to-end: Resolve-ReleaseDecision + Get-NextModuleVersion' {
BeforeAll {
Mock -CommandName Find-PSResource -ModuleName 'Resolve-PSModuleVersion.Helpers' -MockWith { @() }
$emptyReleases = @([PSCustomObject]@{ tagName = 'v0.0.0'; isLatest = $false; isPrerelease = $false })
}
Context '<Name>' -ForEach $TestData.EndToEnd {
BeforeAll {
$config = [PSCustomObject]@{
AutoPatching = $AutoPatching
IncrementalPrerelease = $IncrementalPrerelease
DatePrereleaseFormat = ''
VersionPrefix = $VersionPrefix
ReleaseType = $ReleaseType
IgnoreLabels = @('skip-release')
MajorLabels = @('major')
MinorLabels = @('minor')
PatchLabels = @('patch')
}
$pullRequest = [PSCustomObject]@{
HeadRef = $HeadRef
Labels = $Labels
}
$decision = Resolve-ReleaseDecision -Configuration $config -PullRequest $pullRequest
$latestVer = New-PSSemVer -Version $LatestVersion
$newVersion = Get-NextModuleVersion -LatestVersion $latestVer -Decision $decision `
-Configuration $config -ModuleName 'TestModule' -Releases $emptyReleases
# Derive resolved release type the same way Write-ActionOutput does
$resolvedReleaseType = if ($decision.ShouldPublish) {
if ($decision.CreateRelease) { 'Release' } else { 'Prerelease' }
} else {
'None'
}
}
It 'ShouldPublish is <ExpectedShouldPublish>' {
$decision.ShouldPublish | Should -Be $ExpectedShouldPublish
}
It 'ReleaseType is <ExpectedReleaseType>' {
$resolvedReleaseType | Should -Be $ExpectedReleaseType
}
It 'Version is <ExpectedVersion>' {
"$($newVersion.Major).$($newVersion.Minor).$($newVersion.Patch)" | Should -Be $ExpectedVersion
}
It 'Prerelease is <ExpectedPrerelease>' {
if ([string]::IsNullOrEmpty($ExpectedPrerelease)) {
$newVersion.Prerelease | Should -BeNullOrEmpty
} else {
$newVersion.Prerelease | Should -Be $ExpectedPrerelease
}
}
It 'FullVersion is <ExpectedFullVersion>' {
$newVersion.ToString() | Should -Be $ExpectedFullVersion
}
}
}