Skip to content

Commit 3dacee5

Browse files
authoredFeb 26, 2025··
Merge pull request #661 from SteveL-MSFT/backport-runcommandonset
Backport: `RunCommandOnSet` working in config
2 parents 3275764 + eb84833 commit 3dacee5

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed
 

‎runcommandonset/RunCommandOnSet.dsc.resource.json

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"json",
2020
"set"
2121
],
22+
"implementsPretest": true,
2223
"input": "stdin",
2324
"return": "state"
2425
},

‎runcommandonset/tests/runcommandonset.get.tests.ps1

+20
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,24 @@ Describe 'tests for runcommandonset get' {
3535
'{ "arguments": "foo" }' | dsc resource get -r Microsoft.DSC.Transitional/RunCommandOnSet -f -
3636
$LASTEXITCODE | Should -Be 2
3737
}
38+
39+
It 'Input provided via configuration doc' {
40+
$config_yaml = @"
41+
`$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
42+
resources:
43+
- name: get
44+
type: Microsoft.DSC.Transitional/RunCommandOnSet
45+
properties:
46+
executable: foo
47+
arguments:
48+
- "bar"
49+
"@
50+
$out = $config_yaml | dsc config get -f - | ConvertFrom-Json
51+
$LASTEXITCODE | Should -Be 0
52+
$out.hadErrors | Should -BeFalse
53+
$out.results.Count | Should -Be 1
54+
$out.results[0].type | Should -BeExactly 'Microsoft.DSC.Transitional/RunCommandOnSet'
55+
$out.results[0].result.actualState.executable | Should -BeExactly 'foo'
56+
$out.results[0].result.actualState.arguments[0] | Should -BeExactly 'bar'
57+
}
3858
}

‎runcommandonset/tests/runcommandonset.set.tests.ps1

+25
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,29 @@ Describe 'tests for runcommandonset set' {
8585
$actual | Should -BeLike "*$expected_logging*"
8686
$LASTEXITCODE | Should -Be 2
8787
}
88+
89+
It 'Input provided via configuration doc' {
90+
$command = "Write-Output Hello | Out-File " + $TestDrive + "/output.txt" + " -Append"
91+
$config_yaml = @"
92+
`$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2024/04/config/document.json
93+
resources:
94+
- name: set
95+
type: Microsoft.DSC.Transitional/RunCommandOnSet
96+
properties:
97+
executable: pwsh
98+
arguments:
99+
- -Command
100+
- $command
101+
"@
102+
$out = $config_yaml | dsc config set -f - | ConvertFrom-Json
103+
$LASTEXITCODE | Should -Be 0
104+
$out.hadErrors | Should -BeFalse
105+
$out.results.Count | Should -Be 1
106+
$out.results[0].type | Should -BeExactly 'Microsoft.DSC.Transitional/RunCommandOnSet'
107+
$out.results[0].result.afterState.executable | Should -BeExactly 'pwsh'
108+
$out.results[0].result.afterState.arguments[0] | Should -BeExactly '-Command'
109+
Get-Content $TestDrive/output.txt | Should -BeExactly 'Hello'
110+
$out = $config_yaml | dsc config set -f - | ConvertFrom-Json
111+
Get-Content $TestDrive/output.txt | Should -BeExactly @('Hello', 'Hello')
112+
}
88113
}

0 commit comments

Comments
 (0)
Please sign in to comment.