Skip to content

Commit ecebdb4

Browse files
committed
feat(#161): add tests for Nova release functions and improve parameter handling
- Implement Get-NovaReleaseBoundValueOrDefault function for default value retrieval - Add Test-NovaReleaseBoundSwitch function for switch parameter validation - Enhance existing Get-NovaReleaseRequest function with improved parameter handling - Add test for Get-NovaPackageWorkflowModulePath function
1 parent 0924fb8 commit ecebdb4

2 files changed

Lines changed: 39 additions & 28 deletions

File tree

src/private/release/GetNovaReleaseRequest.ps1

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,31 @@ function Get-NovaReleaseRequestedPath {
1111
return (Get-Location).Path
1212
}
1313

14+
function Get-NovaReleaseBoundValueOrDefault {
15+
[CmdletBinding()]
16+
param(
17+
[Parameter(Mandatory)][hashtable]$BoundParameters,
18+
[Parameter(Mandatory)][string]$Name,
19+
$DefaultValue = $null
20+
)
21+
22+
if ( $BoundParameters.ContainsKey($Name)) {
23+
return $BoundParameters[$Name]
24+
}
25+
26+
return $DefaultValue
27+
}
28+
29+
function Test-NovaReleaseBoundSwitch {
30+
[CmdletBinding()]
31+
param(
32+
[Parameter(Mandatory)][hashtable]$BoundParameters,
33+
[Parameter(Mandatory)][string]$Name
34+
)
35+
36+
return $BoundParameters.ContainsKey($Name) -and [bool]$BoundParameters[$Name]
37+
}
38+
1439
function Get-NovaReleaseRequest {
1540
[CmdletBinding()]
1641
param(
@@ -20,33 +45,13 @@ function Get-NovaReleaseRequest {
2045

2146
return [pscustomobject]@{
2247
ParameterSetName = $ParameterSetName
23-
PublishOption = if ( $BoundParameters.ContainsKey('PublishOption')) {
24-
$BoundParameters.PublishOption
25-
}
26-
else {
27-
@{}
28-
}
29-
LocalRequested = $BoundParameters.ContainsKey('Local') -and [bool]$BoundParameters.Local
30-
Repository = if ( $BoundParameters.ContainsKey('Repository')) {
31-
$BoundParameters.Repository
32-
}
33-
else {
34-
$null
35-
}
36-
ModuleDirectoryPath = if ( $BoundParameters.ContainsKey('ModuleDirectoryPath')) {
37-
$BoundParameters.ModuleDirectoryPath
38-
}
39-
else {
40-
$null
41-
}
42-
ApiKey = if ( $BoundParameters.ContainsKey('ApiKey')) {
43-
$BoundParameters.ApiKey
44-
}
45-
else {
46-
$null
47-
}
48-
SkipTestsRequested = $BoundParameters.ContainsKey('SkipTests') -and $BoundParameters.SkipTests
49-
ContinuousIntegrationRequested = $BoundParameters.ContainsKey('ContinuousIntegration') -and $BoundParameters.ContinuousIntegration
50-
OverrideWarningRequested = $BoundParameters.ContainsKey('OverrideWarning') -and $BoundParameters.OverrideWarning
48+
PublishOption = Get-NovaReleaseBoundValueOrDefault -BoundParameters $BoundParameters -Name 'PublishOption' -DefaultValue @{}
49+
LocalRequested = Test-NovaReleaseBoundSwitch -BoundParameters $BoundParameters -Name 'Local'
50+
Repository = Get-NovaReleaseBoundValueOrDefault -BoundParameters $BoundParameters -Name 'Repository'
51+
ModuleDirectoryPath = Get-NovaReleaseBoundValueOrDefault -BoundParameters $BoundParameters -Name 'ModuleDirectoryPath'
52+
ApiKey = Get-NovaReleaseBoundValueOrDefault -BoundParameters $BoundParameters -Name 'ApiKey'
53+
SkipTestsRequested = Test-NovaReleaseBoundSwitch -BoundParameters $BoundParameters -Name 'SkipTests'
54+
ContinuousIntegrationRequested = Test-NovaReleaseBoundSwitch -BoundParameters $BoundParameters -Name 'ContinuousIntegration'
55+
OverrideWarningRequested = Test-NovaReleaseBoundSwitch -BoundParameters $BoundParameters -Name 'OverrideWarning'
5156
}
5257
}

tests/CoverageGaps.BuildInternals.Tests.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ Describe 'Coverage gaps for build and duplicate-analysis internals' {
9595
}
9696
}
9797

98+
It 'Get-NovaPackageWorkflowModulePath returns the current module path' {
99+
InModuleScope $script:moduleName {
100+
Get-NovaPackageWorkflowModulePath | Should -Be $ExecutionContext.SessionState.Module.Path
101+
}
102+
}
103+
98104
It 'Assert-NovaPublicFunctionFileLayout stops the build when src/public files do not contain exactly one top-level function' {
99105
InModuleScope $script:moduleName {
100106
$projectInfo = [pscustomobject]@{

0 commit comments

Comments
 (0)