diff --git a/runcommandonset/RunCommandOnSet.dsc.resource.json b/runcommandonset/RunCommandOnSet.dsc.resource.json index 121f8677..1b6dd97b 100644 --- a/runcommandonset/RunCommandOnSet.dsc.resource.json +++ b/runcommandonset/RunCommandOnSet.dsc.resource.json @@ -19,6 +19,7 @@ "json", "set" ], + "implementsPretest": true, "input": "stdin", "return": "state" }, diff --git a/runcommandonset/tests/runcommandonset.get.tests.ps1 b/runcommandonset/tests/runcommandonset.get.tests.ps1 index 5955afcc..18b50ac4 100644 --- a/runcommandonset/tests/runcommandonset.get.tests.ps1 +++ b/runcommandonset/tests/runcommandonset.get.tests.ps1 @@ -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' + } } diff --git a/runcommandonset/tests/runcommandonset.set.tests.ps1 b/runcommandonset/tests/runcommandonset.set.tests.ps1 index c6631204..6f38ea0e 100644 --- a/runcommandonset/tests/runcommandonset.set.tests.ps1 +++ b/runcommandonset/tests/runcommandonset.set.tests.ps1 @@ -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') + } }