Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/dsc/psresourceget.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,11 @@ function GetOperation {
[string]$ResourceType
)

if ([string]::IsNullOrEmpty($stdinput)) {
Comment thread
Gijsreyn marked this conversation as resolved.
Write-Trace -level error -message "Get operation requires --input with the resource properties. No input was provided."
exit [ExitCode]::Error
}

$inputObj = $stdinput | ConvertFrom-Json -ErrorAction Stop

Write-Trace -message "Starting Get operation for ResourceType: $ResourceType" -level trace
Expand Down
10 changes: 10 additions & 0 deletions test/DscResource/PSResourceGetDSCResource.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ Describe 'Repository Resource Tests' -Tags 'CI' {
}
}

It 'Get operation without --input exits with a non-zero code and does not produce an unhandled exception' {
$output = & $script:dscExe resource get --resource Microsoft.PowerShell.PSResourceGet/Repository -o json 2>&1
$outputText = $output | Out-String
$LASTEXITCODE | Should -Not -Be 0
$outputText | Should -Match '--input'
$outputText | Should -Match 'required'
$outputText | Should -Not -Match 'Cannot bind argument to parameter'
$outputText | Should -Not -Match 'Unhandled exception'
}

It 'Can delete a Repository resource instance' {
# First, create a repository to delete
Register-PSResourceRepository -Name 'TestRepoToDelete' -uri 'https://www.doesnotexist.com' -ErrorAction SilentlyContinue -APIVersion Local
Expand Down