config-central/tests/Cli.Tests.ps1

18 lines
1010 B
PowerShell

Describe 'CLI error reporting' {
It 'prints a concise error and preserves exit code 2' {
$output = & (Join-Path $PSHOME $(if ($IsWindows) { 'pwsh.exe' } else { 'pwsh' })) -NoProfile -File "$PSScriptRoot/../cc.ps1" plan -Machine missing-test-machine -DataRoot "$TestDrive/data" 2>&1
$LASTEXITCODE | Should -Be 2
($output | Out-String) | Should -Match 'Config Central could not complete:'
($output | Out-String) | Should -Not -Match 'Write-Error:|CategoryInfo|FullyQualifiedErrorId'
}
It 'keeps structured errors available to automation' {
$output = & (Join-Path $PSHOME $(if ($IsWindows) { 'pwsh.exe' } else { 'pwsh' })) -NoProfile -File "$PSScriptRoot/../cc.ps1" plan -Machine missing-test-machine -DataRoot "$TestDrive/data" -Json
$LASTEXITCODE | Should -Be 2
$result = $output | ConvertFrom-Json
$result.succeeded | Should -BeFalse
$result.exitCode | Should -Be 2
$result.error | Should -Not -BeNullOrEmpty
}
}