diff --git a/Public/Array/Get-PfbArraySpace.ps1 b/Public/Array/Get-PfbArraySpace.ps1 index 66688c06..41972daf 100644 --- a/Public/Array/Get-PfbArraySpace.ps1 +++ b/Public/Array/Get-PfbArraySpace.ps1 @@ -7,7 +7,8 @@ function Get-PfbArraySpace { .PARAMETER Array The FlashBlade connection object. If not specified, uses the default connection. .PARAMETER Type - Filter by space type (e.g., 'array', 'file-system', 'object-store'). + Filter by space type. Valid values: 'array', 'file-system', 'object-store'. + Defaults to 'array' if not specified. .EXAMPLE Get-PfbArraySpace #> @@ -17,6 +18,7 @@ function Get-PfbArraySpace { [PSCustomObject]$Array, [Parameter()] + [ValidateSet('array', 'file-system', 'object-store')] [string]$Type ) diff --git a/Tests/Get-PfbArraySpace.Tests.ps1 b/Tests/Get-PfbArraySpace.Tests.ps1 new file mode 100644 index 00000000..a7873e84 --- /dev/null +++ b/Tests/Get-PfbArraySpace.Tests.ps1 @@ -0,0 +1,39 @@ +#Requires -Modules @{ ModuleName = 'Pester'; ModuleVersion = '5.0' } + +BeforeAll { + Import-Module "$PSScriptRoot/../PureStorageFlashBladePowerShell.psd1" -Force + $script:fakeArray = [PSCustomObject]@{ Endpoint = 'fb.example.test'; ApiVersion = '2.0'; AuthToken = 'x' } +} + +Describe 'Get-PfbArraySpace' { + BeforeEach { + Mock -ModuleName PureStorageFlashBladePowerShell Assert-PfbConnection { } + Mock -ModuleName PureStorageFlashBladePowerShell Invoke-PfbApiRequest { } + } + + It 'restricts -Type to the three real spec-documented values' { + $attr = (Get-Command Get-PfbArraySpace).Parameters['Type'].Attributes | + Where-Object { $_ -is [System.Management.Automation.ValidateSetAttribute] } + $attr | Should -Not -BeNullOrEmpty + $attr.ValidValues | Should -Be @('array', 'file-system', 'object-store') + } + + It 'rejects an invalid -Type value before making any API call' { + { Get-PfbArraySpace -Type 'bogus' -Array $fakeArray } | Should -Throw + Should -Invoke Invoke-PfbApiRequest -ModuleName PureStorageFlashBladePowerShell -Times 0 -Exactly + } + + It 'passes a valid -Type through to the query string' { + Get-PfbArraySpace -Type 'file-system' -Array $fakeArray + Should -Invoke Invoke-PfbApiRequest -ModuleName PureStorageFlashBladePowerShell -Times 1 -Exactly -ParameterFilter { + $Method -eq 'GET' -and $Endpoint -eq 'arrays/space' -and $QueryParams['type'] -eq 'file-system' + } + } + + It 'omits -Type from the query string when not specified (server defaults to array)' { + Get-PfbArraySpace -Array $fakeArray + Should -Invoke Invoke-PfbApiRequest -ModuleName PureStorageFlashBladePowerShell -Times 1 -Exactly -ParameterFilter { + -not $QueryParams.ContainsKey('type') + } + } +}