|
| 1 | +BeforeAll { |
| 2 | + $projectRoot = Split-Path -Parent (Split-Path -Parent (Split-Path -Parent $PSScriptRoot)) |
| 3 | + . (Join-Path $projectRoot 'src/private/cli/ConvertFromNovaCliArgument.ps1') |
| 4 | + . (Join-Path $projectRoot 'src/private/cli/GetNovaCliRequiredArgumentValue.ps1') |
| 5 | + |
| 6 | + function ConvertTo-NovaCliArgumentArray {param([hashtable]$BoundParameters, [string[]]$Arguments) return @($Arguments | Where-Object {$_})} |
| 7 | + function Stop-NovaOperation {param([string]$Message, [string]$ErrorId, $Category, $TargetObject) throw $Message} |
| 8 | +} |
| 9 | + |
| 10 | +Describe 'Add-NovaCliDeliveryOption' { |
| 11 | + It 'adds the option when allowed' { |
| 12 | + $options = @{} |
| 13 | + Add-NovaCliDeliveryOption -Options $options -AllowedOptionNameList @('Local') -Option ([pscustomobject]@{Name='Local';Value=$true}) -Token '--local' |
| 14 | + $options.Local | Should -BeTrue |
| 15 | + } |
| 16 | + |
| 17 | + It 'throws when option is not in allowed list' { |
| 18 | + {Add-NovaCliDeliveryOption -Options @{} -AllowedOptionNameList @('Other') -Option ([pscustomobject]@{Name='Local';Value=$true}) -Token '--local'} | Should -Throw '*Unknown argument: --local*' |
| 19 | + } |
| 20 | +} |
| 21 | + |
| 22 | +Describe 'ConvertFrom-NovaCliArgument' { |
| 23 | + It 'parses common delivery flags using the default allowed list' { |
| 24 | + $options = ConvertFrom-NovaCliArgument -Arguments @('--local', '--repository', 'feed', '--api-key', 'KEY', '--skip-tests') |
| 25 | + $options.Local | Should -BeTrue |
| 26 | + $options.Repository | Should -Be 'feed' |
| 27 | + $options.ApiKey | Should -Be 'KEY' |
| 28 | + $options.SkipTests | Should -BeTrue |
| 29 | + } |
| 30 | + |
| 31 | + It 'throws when a flag is not in the allowed list' { |
| 32 | + {ConvertFrom-NovaCliArgument -Arguments @('--local') -AllowedOptionNameList @('Other')} | Should -Throw '*Unknown argument*' |
| 33 | + } |
| 34 | + |
| 35 | + It 'throws for unknown flags' { |
| 36 | + {ConvertFrom-NovaCliArgument -Arguments @('--bogus')} | Should -Throw '*Unknown argument: --bogus*' |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +Describe 'ConvertFrom-NovaPackageCliArgument' { |
| 41 | + It 'restricts the allowed options to package-relevant flags' { |
| 42 | + $options = ConvertFrom-NovaPackageCliArgument -Arguments @('--skip-tests', '--override-warning') |
| 43 | + $options.SkipTests | Should -BeTrue |
| 44 | + $options.OverrideWarning | Should -BeTrue |
| 45 | + } |
| 46 | + |
| 47 | + It 'rejects flags outside the package allow list' { |
| 48 | + {ConvertFrom-NovaPackageCliArgument -Arguments @('--local')} | Should -Throw '*Unknown argument*' |
| 49 | + } |
| 50 | +} |
0 commit comments