@@ -8,143 +8,143 @@ Describe 'registry config set tests' {
88 }
99 }
1010
11- # It 'Can set a deeply nested key and value' -Skip:(!$IsWindows) {
12- # $json = @'
13- # {
14- # "keyPath": "HKCU\\1\\2\\3",
15- # "valueName": "Hello",
16- # "valueData": {
17- # "String": "World"
18- # }
19- # }
20- # '@
21- # $out = registry config set --input $json 2>$null
22- # $LASTEXITCODE | Should -Be 0
23- # $out | Should -BeNullOrEmpty
24- # $result = registry config get --input $json 2>$null | ConvertFrom-Json
25- # $result.keyPath | Should -Be 'HKCU\1\2\3'
26- # $result.valueName | Should -Be 'Hello'
27- # $result.valueData.String | Should -Be 'World'
28- # ($result.psobject.properties | Measure-Object).Count | Should -Be 3
29-
30- # $out = registry config get --input $json 2>$null
31- # $LASTEXITCODE | Should -Be 0
32- # $result = $out | ConvertFrom-Json
33- # $result.keyPath | Should -Be 'HKCU\1\2\3'
34- # $result.valueName | Should -Be 'Hello'
35- # $result.valueData.String | Should -Be 'World'
36- # ($result.psobject.properties | Measure-Object).Count | Should -Be 3
37- # }
38-
39- # It 'delete called when _exist is false' -Skip:(!$IsWindows) {
40- # $config = @{
41- # '$schema' = 'https://aka.ms/dsc/schemas/v3/bundled/config/document.json'
42- # resources = @(
43- # @{
44- # name = 'reg'
45- # type = 'Microsoft.Windows/Registry'
46- # properties = @{
47- # keyPath = 'HKCU\1\2'
48- # valueName = 'Test'
49- # valueData = @{
50- # String = 'Test'
51- # }
52- # _exist = $true
53- # }
54- # }
55- # )
56- # }
57-
58- # $out = dsc config set -i ($config | ConvertTo-Json -Depth 10)
59- # $LASTEXITCODE | Should -Be 0
60-
61- # $config.resources[0].properties._exist = $false
62- # $out = dsc config set -i ($config | ConvertTo-Json -Depth 10) | ConvertFrom-Json
63- # $LASTEXITCODE | Should -Be 0
64- # $out.results[0].result.afterState._exist | Should -Be $false
65-
66- # Get-ItemProperty -Path 'HKCU:\1\2' -Name 'Test' -ErrorAction Ignore | Should -BeNullOrEmpty
67-
68- # $config.resources[0].properties.valueName = $null
69- # $out = dsc config set -i ($config | ConvertTo-Json -Depth 10) | ConvertFrom-Json
70- # $LASTEXITCODE | Should -Be 0
71- # $out.results[0].result.afterState._exist | Should -Be $false
72-
73- # Get-Item -Path 'HKCU:\1\2' -ErrorAction Ignore | Should -BeNullOrEmpty
74- # }
75-
76- # It 'Can set value without data' -Skip:(!$IsWindows) {
77- # $configYaml = @'
78- # $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
79- # resources:
80- # - name: Key
81- # type: Microsoft.Windows/Registry
82- # properties:
83- # keyPath: 'HKCU\1'
84- # valueName: Test
85- # _exist: true
86- # '@
87-
88- # $out = dsc config set -i $configYaml | ConvertFrom-Json
89- # $LASTEXITCODE | Should -Be 0
90- # $out.results[0].result.afterState.keyPath | Should -BeExactly 'HKCU\1'
91- # $out.results[0].result.afterState.valueName | Should -BeExactly 'Test'
92- # $out.results[0].result.afterState.valueData | Should -BeNullOrEmpty
93-
94- # $out = dsc config get -i $configYaml | ConvertFrom-Json
95- # $LASTEXITCODE | Should -Be 0
96- # $out.results[0].result.actualState.keyPath | Should -BeExactly 'HKCU\1'
97- # $out.results[0].result.actualState.valueName | Should -BeExactly 'Test'
98- # $out.results[0].result.actualState.valueData | Should -BeNullOrEmpty
99-
100- # Remove-Item -Path 'HKCU:\1' -Recurse -ErrorAction Ignore
101- # }
102-
103- # It 'Should succeed when _exist is false and value does not exist' -Skip:(!$IsWindows) {
104- # $config = @{
105- # '$schema' = 'https://aka.ms/dsc/schemas/v3/bundled/config/document.json'
106- # resources = @(
107- # @{
108- # name = 'reg'
109- # type = 'Microsoft.Windows/Registry'
110- # properties = @{
111- # keyPath = 'HKCU'
112- # valueName = 'Test'
113- # valueData = @{
114- # String = 'Test'
115- # }
116- # _exist = $false
117- # }
118- # }
119- # )
120- # }
121-
122- # $out = dsc config set -i ($config | ConvertTo-Json -Depth 10) | ConvertFrom-Json
123- # $LASTEXITCODE | Should -Be 0
124- # $out.results[0].result.afterState._exist | Should -Be $false
125-
126- # Get-ItemProperty -Path 'HKCU:\1\2' -Name 'Test' -ErrorAction Ignore | Should -BeNullOrEmpty
127- # }
128-
129- # It 'Should succeed when _exist is false and key does not exist' -Skip:(!$IsWindows) {
130- # $config = @{
131- # '$schema' = 'https://aka.ms/dsc/schemas/v3/bundled/config/document.json'
132- # resources = @(
133- # @{
134- # name = 'reg'
135- # type = 'Microsoft.Windows/Registry'
136- # properties = @{
137- # keyPath = 'HKCU\1'
138- # _exist = $false
139- # }
140- # }
141- # )
142- # }
143-
144- # $out = dsc config set -i ($config | ConvertTo-Json -Depth 10) | ConvertFrom-Json
145- # $LASTEXITCODE | Should -Be 0
146- # $out.results[0].result.afterState._exist | Should -Be $false
147- # }
11+ It ' Can set a deeply nested key and value' - Skip:(! $IsWindows ) {
12+ $json = @'
13+ {
14+ "keyPath": "HKCU\\1\\2\\3",
15+ "valueName": "Hello",
16+ "valueData": {
17+ "String": "World"
18+ }
19+ }
20+ '@
21+ $out = registry config set -- input $json 2> $null
22+ $LASTEXITCODE | Should - Be 0
23+ $out | Should - BeNullOrEmpty
24+ $result = registry config get -- input $json 2> $null | ConvertFrom-Json
25+ $result.keyPath | Should - Be ' HKCU\1\2\3'
26+ $result.valueName | Should - Be ' Hello'
27+ $result.valueData.String | Should - Be ' World'
28+ ($result.psobject.properties | Measure-Object ).Count | Should - Be 3
29+
30+ $out = registry config get -- input $json 2> $null
31+ $LASTEXITCODE | Should - Be 0
32+ $result = $out | ConvertFrom-Json
33+ $result.keyPath | Should - Be ' HKCU\1\2\3'
34+ $result.valueName | Should - Be ' Hello'
35+ $result.valueData.String | Should - Be ' World'
36+ ($result.psobject.properties | Measure-Object ).Count | Should - Be 3
37+ }
38+
39+ It ' delete called when _exist is false' - Skip:(! $IsWindows ) {
40+ $config = @ {
41+ ' $schema' = ' https://aka.ms/dsc/schemas/v3/bundled/config/document.json'
42+ resources = @ (
43+ @ {
44+ name = ' reg'
45+ type = ' Microsoft.Windows/Registry'
46+ properties = @ {
47+ keyPath = ' HKCU\1\2'
48+ valueName = ' Test'
49+ valueData = @ {
50+ String = ' Test'
51+ }
52+ _exist = $true
53+ }
54+ }
55+ )
56+ }
57+
58+ $out = dsc config set - i ($config | ConvertTo-Json - Depth 10 )
59+ $LASTEXITCODE | Should - Be 0
60+
61+ $config.resources [0 ].properties._exist = $false
62+ $out = dsc config set - i ($config | ConvertTo-Json - Depth 10 ) | ConvertFrom-Json
63+ $LASTEXITCODE | Should - Be 0
64+ $out.results [0 ].result.afterState._exist | Should - Be $false
65+
66+ Get-ItemProperty - Path ' HKCU:\1\2' - Name ' Test' - ErrorAction Ignore | Should - BeNullOrEmpty
67+
68+ $config.resources [0 ].properties.valueName = $null
69+ $out = dsc config set - i ($config | ConvertTo-Json - Depth 10 ) | ConvertFrom-Json
70+ $LASTEXITCODE | Should - Be 0
71+ $out.results [0 ].result.afterState._exist | Should - Be $false
72+
73+ Get-Item - Path ' HKCU:\1\2' - ErrorAction Ignore | Should - BeNullOrEmpty
74+ }
75+
76+ It ' Can set value without data' - Skip:(! $IsWindows ) {
77+ $configYaml = @'
78+ $schema: https://aka.ms/dsc/schemas/v3/bundled/config/document.json
79+ resources:
80+ - name: Key
81+ type: Microsoft.Windows/Registry
82+ properties:
83+ keyPath: 'HKCU\1'
84+ valueName: Test
85+ _exist: true
86+ '@
87+
88+ $out = dsc config set - i $configYaml | ConvertFrom-Json
89+ $LASTEXITCODE | Should - Be 0
90+ $out.results [0 ].result.afterState.keyPath | Should - BeExactly ' HKCU\1'
91+ $out.results [0 ].result.afterState.valueName | Should - BeExactly ' Test'
92+ $out.results [0 ].result.afterState.valueData | Should - BeNullOrEmpty
93+
94+ $out = dsc config get - i $configYaml | ConvertFrom-Json
95+ $LASTEXITCODE | Should - Be 0
96+ $out.results [0 ].result.actualState.keyPath | Should - BeExactly ' HKCU\1'
97+ $out.results [0 ].result.actualState.valueName | Should - BeExactly ' Test'
98+ $out.results [0 ].result.actualState.valueData | Should - BeNullOrEmpty
99+
100+ Remove-Item - Path ' HKCU:\1' - Recurse - ErrorAction Ignore
101+ }
102+
103+ It ' Should succeed when _exist is false and value does not exist' - Skip:(! $IsWindows ) {
104+ $config = @ {
105+ ' $schema' = ' https://aka.ms/dsc/schemas/v3/bundled/config/document.json'
106+ resources = @ (
107+ @ {
108+ name = ' reg'
109+ type = ' Microsoft.Windows/Registry'
110+ properties = @ {
111+ keyPath = ' HKCU'
112+ valueName = ' Test'
113+ valueData = @ {
114+ String = ' Test'
115+ }
116+ _exist = $false
117+ }
118+ }
119+ )
120+ }
121+
122+ $out = dsc config set - i ($config | ConvertTo-Json - Depth 10 ) | ConvertFrom-Json
123+ $LASTEXITCODE | Should - Be 0
124+ $out.results [0 ].result.afterState._exist | Should - Be $false
125+
126+ Get-ItemProperty - Path ' HKCU:\1\2' - Name ' Test' - ErrorAction Ignore | Should - BeNullOrEmpty
127+ }
128+
129+ It ' Should succeed when _exist is false and key does not exist' - Skip:(! $IsWindows ) {
130+ $config = @ {
131+ ' $schema' = ' https://aka.ms/dsc/schemas/v3/bundled/config/document.json'
132+ resources = @ (
133+ @ {
134+ name = ' reg'
135+ type = ' Microsoft.Windows/Registry'
136+ properties = @ {
137+ keyPath = ' HKCU\1'
138+ _exist = $false
139+ }
140+ }
141+ )
142+ }
143+
144+ $out = dsc config set - i ($config | ConvertTo-Json - Depth 10 ) | ConvertFrom-Json
145+ $LASTEXITCODE | Should - Be 0
146+ $out.results [0 ].result.afterState._exist | Should - Be $false
147+ }
148148
149149 It ' Can delete value from system-protected key with minimal permissions' - Skip:(! $IsWindows ) {
150150 $testKeyPath = ' HKLM:\Software\Policies\Microsoft\Windows\Appx'
0 commit comments