From a8a73469bbf3abf2a0878077223a91e03add8221 Mon Sep 17 00:00:00 2001 From: Tess Gauthier <tessgauthier@microsoft.com> Date: Tue, 25 Feb 2025 16:11:03 -0500 Subject: [PATCH 1/2] add tests for config passed to RunCommandOnSet --- .../tests/runcommandonset.get.tests.ps1 | 20 +++++++++++++++ .../tests/runcommandonset.set.tests.ps1 | 25 +++++++++++++++++++ 2 files changed, 45 insertions(+) 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') + } } From 12d9fb6546bdf80d72f07762b5953f49dc117e6c Mon Sep 17 00:00:00 2001 From: Tess Gauthier <tessgauthier@microsoft.com> Date: Tue, 25 Feb 2025 16:11:39 -0500 Subject: [PATCH 2/2] add implementsPreTest to RunCommandOnSet --- runcommandonset/RunCommandOnSet.dsc.resource.json | 1 + 1 file changed, 1 insertion(+) 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" },