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
11 changes: 10 additions & 1 deletion adapters/powershell/Tests/TestAdapter/testadapter.resource.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ switch ($Operation) {
)} | ConvertTo-Json -Depth 10 -Compress
}
'Validate' {
@{ valid = $true } | ConvertTo-Json
# Test validation with reason field
if ($inputobj.resources[0].properties.TestCaseId -eq 99) {
@{
valid = $false
reason = "TestCaseId 99 is not allowed for testing purposes"
} | ConvertTo-Json
}
else {
@{ valid = $true } | ConvertTo-Json
}
}
}
17 changes: 17 additions & 0 deletions adapters/powershell/Tests/powershellgroup.resource.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,23 @@ Describe 'PowerShell adapter resource tests' {
}
}

It 'Verify validate operation shows reason on adapted resource' {
$oldPath = $env:PATH
try {
$adapterPath = Join-Path $PSScriptRoot 'TestAdapter'
$env:PATH += [System.IO.Path]::PathSeparator + $adapterPath

# Test with invalid TestCaseId that should trigger validation failure with reason
$r = '{"TestCaseId": 99}' | dsc resource get -r 'Test/TestCase' -f - 2>&1
$LASTEXITCODE | Should -Not -Be 0
$errorOutput = $r | Out-String
$errorOutput | Should -Match "TestCaseId 99 is not allowed for testing purposes"
}
finally {
$env:PATH = $oldPath
}
}

It 'Dsc can process large resource output' -Pending {
try {
$env:TestClassResourceResultCount = 5000 # with sync resource invocations this was not possible
Expand Down
3 changes: 2 additions & 1 deletion lib/dsc-lib/src/dscresources/command_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,8 @@ fn verify_json(resource: &ResourceManifest, cwd: &Path, json: &str) -> Result<()
return Ok(());
}

return Err(DscError::Validation(t!("dscresources.commandResource.resourceInvalidJson").to_string()));
let reason = result.reason.unwrap_or_else(|| t!("dscresources.commandResource.resourceInvalidJson").to_string());
return Err(DscError::Validation(reason));
}

// otherwise, use schema validation
Expand Down