From fa9c0b0e7f15beab104a894bc7687e6fa4acce3a Mon Sep 17 00:00:00 2001 From: Justin Emerson Date: Thu, 16 Jul 2026 19:01:34 +0100 Subject: [PATCH] Add ValidateSet to Get-PfbArraySpace -Type The server-side arrays/space endpoint silently returns an empty space object for any unrecognized -Type value instead of erroring (verified live on FB-A: -Type all and -Type garbage-value both returned an empty result with no error). Add a client-side [ValidateSet(''array'', ''file-system'', ''object-store'')] so invalid values fail fast with a clear error before any HTTP call is made, and tighten the .PARAMETER Type help text to state the exact valid values and default. Adds Tests/Get-PfbArraySpace.Tests.ps1 (no prior test coverage existed for this cmdlet) covering the ValidateSet attribute, rejection of an invalid value with zero API calls, pass-through of a valid value, and omission of -Type from the query string when unspecified. Live-verified against FB-A (10.21.243.66): -Type array/file-system/ object-store still return real, distinct data; -Type all and -Type garbage-value now throw immediately client-side with no HTTP call. --- Public/Array/Get-PfbArraySpace.ps1 | 4 ++- Tests/Get-PfbArraySpace.Tests.ps1 | 39 ++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 Tests/Get-PfbArraySpace.Tests.ps1 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') + } + } +}