Skip to content
Merged
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
1 change: 1 addition & 0 deletions runcommandonset/RunCommandOnSet.dsc.resource.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"json",
"set"
],
"implementsPretest": true,
"input": "stdin",
"return": "state"
},
Expand Down
20 changes: 20 additions & 0 deletions runcommandonset/tests/runcommandonset.get.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,24 @@ Describe 'tests for runcommandonset get' {
'{ "arguments": "foo" }' | dsc resource get -r Microsoft.DSC.Transitional/RunCommandOnSet -f -
$LASTEXITCODE | Should -Be 2
}

It 'Input provided via configuration doc' {
$config_yaml = @"
`$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
resources:
- name: get
type: Microsoft.DSC.Transitional/RunCommandOnSet
properties:
executable: foo
arguments:
- "bar"
"@
$out = $config_yaml | dsc config get -f - | ConvertFrom-Json
$LASTEXITCODE | Should -Be 0
$out.hadErrors | Should -BeFalse
$out.results.Count | Should -Be 1
$out.results[0].type | Should -BeExactly 'Microsoft.DSC.Transitional/RunCommandOnSet'
$out.results[0].result.actualState.executable | Should -BeExactly 'foo'
$out.results[0].result.actualState.arguments[0] | Should -BeExactly 'bar'
}
}
25 changes: 25 additions & 0 deletions runcommandonset/tests/runcommandonset.set.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,29 @@ Describe 'tests for runcommandonset set' {
$actual | Should -BeLike "*$expected_logging*"
$LASTEXITCODE | Should -Be 2
}

It 'Input provided via configuration doc' {
$command = "Write-Output Hello | Out-File " + $TestDrive + "/output.txt" + " -Append"
$config_yaml = @"
`$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
resources:
- name: set
type: Microsoft.DSC.Transitional/RunCommandOnSet
properties:
executable: pwsh
arguments:
- -Command
- $command
"@
$out = $config_yaml | dsc config set -f - | ConvertFrom-Json
$LASTEXITCODE | Should -Be 0
$out.hadErrors | Should -BeFalse
$out.results.Count | Should -Be 1
$out.results[0].type | Should -BeExactly 'Microsoft.DSC.Transitional/RunCommandOnSet'
$out.results[0].result.afterState.executable | Should -BeExactly 'pwsh'
$out.results[0].result.afterState.arguments[0] | Should -BeExactly '-Command'
Get-Content $TestDrive/output.txt | Should -BeExactly 'Hello'
$out = $config_yaml | dsc config set -f - | ConvertFrom-Json
Get-Content $TestDrive/output.txt | Should -BeExactly @('Hello', 'Hello')
}
}