-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #400 from tgauth/add-whatif
Add whatif
- Loading branch information
Showing
12 changed files
with
169 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
Describe 'whatif tests' { | ||
AfterEach { | ||
if ($IsWindows) { | ||
Remove-Item -Path 'HKCU:\1' -Recurse -ErrorAction Ignore | ||
} | ||
} | ||
|
||
It 'config set whatif when actual state matches desired state' { | ||
$config_yaml = @" | ||
`$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/10/config/document.json | ||
resources: | ||
- name: Hello | ||
type: Test/Echo | ||
properties: | ||
output: hello | ||
"@ | ||
$what_if_result = $config_yaml | dsc config set -w | ConvertFrom-Json | ||
$set_result = $config_yaml | dsc config set | ConvertFrom-Json | ||
$what_if_result.metadata.'Microsoft.DSC'.executionType | Should -BeExactly 'WhatIf' | ||
$what_if_result.results.result.beforeState.output | Should -Be $set_result.results.result.beforeState.output | ||
$what_if_result.results.result.afterState.output | Should -Be $set_result.results.result.afterState.output | ||
$what_if_result.results.result.changedProperties | Should -Be $set_result.results.result.changedProperties | ||
$what_if_result.hadErrors | Should -BeFalse | ||
$what_if_result.results.Count | Should -Be 1 | ||
$LASTEXITCODE | Should -Be 0 | ||
} | ||
|
||
It 'config set whatif when actual state does not match desired state' -Skip:(!$IsWindows) { | ||
# TODO: change/create cross-plat resource that implements set without just matching desired state | ||
$config_yaml = @" | ||
`$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/10/config/document.json | ||
resources: | ||
- name: Registry | ||
type: Microsoft.Windows/Registry | ||
properties: | ||
keyPath: 'HKCU\1\2' | ||
"@ | ||
$what_if_result = $config_yaml | dsc config set -w | ConvertFrom-Json | ||
$set_result = $config_yaml | dsc config set | ConvertFrom-Json | ||
$what_if_result.metadata.'Microsoft.DSC'.executionType | Should -BeExactly 'WhatIf' | ||
$what_if_result.results.result.beforeState._exist | Should -Be $set_result.results.result.beforeState._exist | ||
$what_if_result.results.result.beforeState.keyPath | Should -Be $set_result.results.result.beforeState.keyPath | ||
$what_if_result.results.result.afterState.KeyPath | Should -Be $set_result.results.result.afterState.keyPath | ||
$what_if_result.results.result.changedProperties | Should -Be $set_result.results.result.changedProperties | ||
$what_if_result.hadErrors | Should -BeFalse | ||
$what_if_result.results.Count | Should -Be 1 | ||
$LASTEXITCODE | Should -Be 0 | ||
|
||
} | ||
|
||
It 'config set whatif for delete is not supported' { | ||
$config_yaml = @" | ||
`$schema: https://raw.githubusercontent.com/PowerShell/DSC/main/schemas/2023/10/config/document.json | ||
resources: | ||
- name: Delete | ||
type: Test/Delete | ||
properties: | ||
_exist: false | ||
"@ | ||
$result = $config_yaml | dsc config set -w 2>&1 | ||
$result | Should -Match 'ERROR.*?Not supported.*?what-if' | ||
$LASTEXITCODE | Should -Be 2 | ||
} | ||
|
||
It 'config set whatif for group resource' { | ||
$result = dsc config set -p $PSScriptRoot/../examples/groups.dsc.yaml -w 2>&1 | ||
$result | Should -Match 'ERROR.*?Not implemented.*?what-if' | ||
$LASTEXITCODE | Should -Be 2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.