chef 18.6.2 → 18.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +5 -5
- data/chef.gemspec +17 -13
- data/lib/chef/compliance/default_attributes.rb +2 -2
- data/lib/chef/compliance/runner.rb +6 -1
- data/lib/chef/cookbook/metadata.rb +1 -1
- data/lib/chef/cookbook/remote_file_vendor.rb +1 -4
- data/lib/chef/event_dispatch/dispatcher.rb +0 -1
- data/lib/chef/provider/package/dnf/dnf_helper.py +7 -0
- data/lib/chef/provider/package/snap.rb +1 -1
- data/lib/chef/provider/registry_key.rb +6 -0
- data/lib/chef/resource/apt_repository.rb +85 -12
- data/lib/chef/resource/registry_key.rb +18 -0
- data/lib/chef/resource.rb +1 -0
- data/lib/chef/resource_reporter.rb +1 -0
- data/lib/chef/util/powershell/ps_credential.rb +10 -0
- data/lib/chef/version.rb +1 -1
- data/lib/chef/win32/registry.rb +0 -1
- data/spec/functional/assets/yumrepo-empty/repodata/repomd.xml +6 -6
- data/spec/functional/resource/registry_spec.rb +276 -609
- data/spec/tiny_server.rb +5 -2
- data/spec/unit/provider/apt_repository_spec.rb +13 -8
- data/spec/unit/provider/registry_key_spec.rb +18 -17
- data/spec/unit/util/powershell/ps_credential_spec.rb +6 -0
- metadata +22 -22
- /data/spec/functional/assets/yumrepo-empty/repodata/{01a3b489a465bcac22a43492163df43451dc6ce47d27f66de289756b91635523-filelists.sqlite.bz2 → 01a3b-filelists.sqlite.bz2} +0 -0
- /data/spec/functional/assets/yumrepo-empty/repodata/{401dc19bda88c82c403423fb835844d64345f7e95f5b9835888189c03834cc93-filelists.xml.gz → 401dc-filelists.xml.gz} +0 -0
- /data/spec/functional/assets/yumrepo-empty/repodata/{5dc1e6e73c84803f059bb3065e684e56adfc289a7e398946574d79dac6643945-primary.sqlite.bz2 → 5dc1e-primary.sqlite.bz2} +0 -0
- /data/spec/functional/assets/yumrepo-empty/repodata/{6bf9672d0862e8ef8b8ff05a2fd0208a922b1f5978e6589d87944c88259cb670-other.xml.gz → 6bf96-other.xml.gz} +0 -0
- /data/spec/functional/assets/yumrepo-empty/repodata/{7c36572015e075add2b38b900837bcdbb8a504130ddff49b2351a7fc0affa3d4-other.sqlite.bz2 → 7c365-other.sqlite.bz2} +0 -0
- /data/spec/functional/assets/yumrepo-empty/repodata/{dabe2ce5481d23de1f4f52bdcfee0f9af98316c9e0de2ce8123adeefa0dd08b9-primary.xml.gz → dabe2-primary.xml.gz} +0 -0
@@ -1,7 +1,6 @@
|
|
1
1
|
#
|
2
|
-
# Author::
|
3
|
-
#
|
4
|
-
# Copyright:: Copyright (c) Chef Software Inc.
|
2
|
+
# Author:: Thomas Powell (<powell@progress.com>)
|
3
|
+
# Copyright:: Copyright (c) 2025 Progress Chef Software Inc.
|
5
4
|
# License:: Apache License, Version 2.0
|
6
5
|
#
|
7
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -17,53 +16,67 @@
|
|
17
16
|
# limitations under the License.
|
18
17
|
#
|
19
18
|
|
20
|
-
require "chef/win32/registry"
|
21
|
-
require "chef/resource_reporter"
|
22
19
|
require "spec_helper"
|
23
20
|
|
24
|
-
describe Chef::Resource::RegistryKey
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
ohai.all_plugins
|
30
|
-
node.consume_external_attrs(ohai.data, {})
|
31
|
-
run_context = Chef::RunContext.new(node, {}, events)
|
32
|
-
@resource = Chef::Resource::RegistryKey.new("HKCU\\Software", run_context)
|
33
|
-
end
|
34
|
-
context "when load_current_resource is run on a non-windows node" do
|
35
|
-
it "throws an exception because you don't have a windows registry (derp)" do
|
36
|
-
@resource.key("HKCU\\Software\\Opscode")
|
37
|
-
@resource.values([{ name: "Color", type: :string, data: "Orange" }])
|
38
|
-
expect { @resource.run_action(:create) }.to raise_error(Chef::Exceptions::Win32NotWindows)
|
21
|
+
describe Chef::Resource::RegistryKey do
|
22
|
+
around(:example) do |example|
|
23
|
+
original_method = described_class.instance_method(:scrub_values)
|
24
|
+
described_class.define_method(:scrub_values) do |values|
|
25
|
+
values
|
39
26
|
end
|
27
|
+
example.run
|
28
|
+
described_class.define_method(original_method.name, original_method)
|
40
29
|
end
|
41
|
-
end
|
42
30
|
|
43
|
-
|
31
|
+
let(:events) { Chef::EventDispatch::Dispatcher.new }
|
32
|
+
let(:node) { Chef::Node.new }
|
33
|
+
let(:ohai) { Ohai::System.new }
|
34
|
+
let(:run_context) { Chef::RunContext.new(node, {}, events) }
|
35
|
+
let(:new_resource) { Chef::Resource::RegistryKey.new(resource_name, run_context) }
|
44
36
|
|
45
|
-
# parent and key must be single keys, not paths
|
46
37
|
let(:parent) { "Opscode" }
|
47
38
|
let(:child) { "Whatever" }
|
48
|
-
let(:key_parent) { "
|
49
|
-
let(:key_child) { "
|
50
|
-
|
51
|
-
let(:
|
52
|
-
let(:reg_child) { "HKLM\\" + key_child }
|
39
|
+
let(:key_parent) { "Software\\#{parent}" }
|
40
|
+
let(:key_child) { "#{key_parent}\\#{child}" }
|
41
|
+
let(:reg_parent) { "HKLM\\#{key_parent}" }
|
42
|
+
let(:reg_child) { "HKLM\\#{key_child}" }
|
53
43
|
let(:hive_class) { ::Win32::Registry::HKEY_LOCAL_MACHINE }
|
54
44
|
let(:resource_name) { "This is the name of my Resource" }
|
55
45
|
|
46
|
+
let(:events) { Chef::EventDispatch::Dispatcher.new }
|
47
|
+
let(:run_context) { Chef::RunContext.new(node, {}, events) }
|
48
|
+
let(:registry) { Chef::Win32::Registry.new(run_context) }
|
49
|
+
|
50
|
+
let(:node_name) { "windowsbox" }
|
51
|
+
let(:run_id) { SecureRandom.uuid }
|
52
|
+
let(:events) { Chef::EventDispatch::Dispatcher.new }
|
53
|
+
let(:run_status) { Chef::RunStatus.new(node, events) }
|
54
|
+
let(:action_collection) { Chef::ActionCollection.new(events) }
|
55
|
+
|
56
|
+
let(:rest_client) do
|
57
|
+
rest_client = double("Chef::ServerAPI")
|
58
|
+
|
59
|
+
# allow().to receive(:message).with(::any arguments::) syntax seems to be broken here
|
60
|
+
allow(rest_client).to receive(:post).and_return("uri" => "https://example.com/reports/nodes/#{node_name}/runs/#{run_id}")
|
61
|
+
allow(rest_client).to receive(:create_url).and_return("reports/nodes/#{node_name}/run/#{run_id}")
|
62
|
+
allow(rest_client).to receive(:raw_http_request).and_return({ "result" => "ok" })
|
63
|
+
|
64
|
+
rest_client
|
65
|
+
end
|
66
|
+
|
67
|
+
let(:resource_reporter) { Chef::ResourceReporter.new(rest_client) }
|
68
|
+
|
56
69
|
def clean_registry
|
57
70
|
if windows64?
|
58
71
|
# clean 64-bit space on WOW64
|
59
|
-
|
60
|
-
|
61
|
-
|
72
|
+
registry.architecture = :x86_64
|
73
|
+
registry.delete_key(reg_parent, true)
|
74
|
+
registry.architecture = :machine
|
62
75
|
end
|
63
76
|
# clean 32-bit space on WOW64
|
64
|
-
|
65
|
-
|
66
|
-
|
77
|
+
registry.architecture = :i386
|
78
|
+
registry.delete_key(reg_parent, true)
|
79
|
+
registry.architecture = :machine
|
67
80
|
end
|
68
81
|
|
69
82
|
def reset_registry
|
@@ -72,604 +85,258 @@ describe Chef::Resource::RegistryKey, :windows_only, broken: true do
|
|
72
85
|
hive_class.create(key_parent, Win32::Registry::KEY_WRITE | 0x0200)
|
73
86
|
end
|
74
87
|
|
75
|
-
|
76
|
-
|
77
|
-
[
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
reg["AKA", Win32::Registry::REG_SZ] = "OC"
|
83
|
-
end
|
84
|
-
hive_class.create(key_parent + "\\ReportKey", Win32::Registry::KEY_WRITE | flag)
|
85
|
-
hive_class.open(key_parent + "\\ReportKey", Win32::Registry::KEY_ALL_ACCESS | flag) do |reg|
|
86
|
-
reg["ReportVal4", Win32::Registry::REG_SZ] = "report4"
|
87
|
-
reg["ReportVal5", Win32::Registry::REG_SZ] = "report5"
|
88
|
-
end
|
89
|
-
hive_class.create(key_parent + "\\OpscodeWhyRun", Win32::Registry::KEY_WRITE | flag)
|
90
|
-
hive_class.open(key_parent + "\\OpscodeWhyRun", Win32::Registry::KEY_ALL_ACCESS | flag) do |reg|
|
91
|
-
reg["BriskWalk", Win32::Registry::REG_SZ] = "is good for health"
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
before(:all) do
|
97
|
-
@events = Chef::EventDispatch::Dispatcher.new
|
98
|
-
@node = Chef::Node.new
|
99
|
-
ohai = Ohai::System.new
|
100
|
-
ohai.all_plugins
|
101
|
-
@node.consume_external_attrs(ohai.data, {})
|
102
|
-
@run_context = Chef::RunContext.new(@node, {}, @events)
|
103
|
-
|
104
|
-
@new_resource = Chef::Resource::RegistryKey.new(resource_name, @run_context)
|
105
|
-
@registry = Chef::Win32::Registry.new(@run_context)
|
106
|
-
|
107
|
-
reset_registry
|
108
|
-
end
|
109
|
-
|
110
|
-
# Reporting setup
|
111
|
-
before do
|
112
|
-
@node.name("windowsbox")
|
113
|
-
|
114
|
-
@rest_client = double("Chef::ServerAPI (mock)")
|
115
|
-
allow(@rest_client).to receive(:create_url).and_return("reports/nodes/windowsbox/runs/#{@run_id}")
|
116
|
-
allow(@rest_client).to receive(:raw_http_request).and_return({ "result" => "ok" })
|
117
|
-
allow(@rest_client).to receive(:post_rest).and_return({ "uri" => "https://example.com/reports/nodes/windowsbox/runs/#{@run_id}" })
|
118
|
-
|
119
|
-
@resource_reporter = Chef::ResourceReporter.new(@rest_client)
|
120
|
-
@events.register(@resource_reporter)
|
121
|
-
@run_status = Chef::RunStatus.new(@node, @events)
|
122
|
-
@resource_reporter.run_started(@run_status)
|
123
|
-
@run_id = @resource_reporter.run_id
|
124
|
-
|
125
|
-
@new_resource.cookbook_name = "monkey"
|
126
|
-
@cookbook_version = double("Cookbook::Version", version: "1.2.3")
|
127
|
-
@new_resource.cookbook_version(@cookbook_version)
|
128
|
-
end
|
129
|
-
|
130
|
-
after(:all) do
|
131
|
-
clean_registry
|
132
|
-
end
|
133
|
-
|
134
|
-
context "when action is create" do
|
135
|
-
before(:all) do
|
136
|
-
reset_registry
|
137
|
-
end
|
138
|
-
it "creates registry key, value if the key is missing" do
|
139
|
-
@new_resource.key(reg_child)
|
140
|
-
@new_resource.values([{ name: "Color", type: :string, data: "Orange" }])
|
141
|
-
@new_resource.run_action(:create)
|
142
|
-
|
143
|
-
expect(@registry.key_exists?(reg_child)).to eq(true)
|
144
|
-
expect(@registry.data_exists?(reg_child, { name: "Color", type: :string, data: "Orange" })).to eq(true)
|
88
|
+
context "when running on non-Windows", :unix_only do
|
89
|
+
let(:registry_key) { "HKCU\\Software\\Opscode" }
|
90
|
+
let(:registry_key_values) { [{ name: "Color", type: :string, data: "Orange" }] }
|
91
|
+
subject do
|
92
|
+
new_resource.key(registry_key)
|
93
|
+
new_resource.values(registry_key_values)
|
94
|
+
new_resource.run_action(:create)
|
145
95
|
end
|
146
|
-
|
147
|
-
|
148
|
-
@new_resource.key(reg_child)
|
149
|
-
@new_resource.values([{ name: "Color", type: :string, data: "Orange" }])
|
150
|
-
@new_resource.run_action(:create)
|
151
|
-
|
152
|
-
expect(@registry.key_exists?(reg_child)).to eq(true)
|
153
|
-
expect(@registry.data_exists?(reg_child, { name: "Color", type: :string, data: "Orange" })).to eq(true)
|
154
|
-
end
|
155
|
-
|
156
|
-
it "does not create the key if it already exists with same value and type but datatype of data differs" do
|
157
|
-
@new_resource.key(reg_child)
|
158
|
-
@new_resource.values([{ name: "number", type: :dword, data: "12345" }])
|
159
|
-
@new_resource.run_action(:create)
|
160
|
-
|
161
|
-
expect(@new_resource).not_to be_updated_by_last_action
|
162
|
-
expect(@registry.key_exists?(reg_child)).to eq(true)
|
163
|
-
expect(@registry.data_exists?(reg_child, { name: "number", type: :dword, data: 12344 })).to eq(true)
|
164
|
-
end
|
165
|
-
|
166
|
-
it "creates a value if it does not exist" do
|
167
|
-
@new_resource.key(reg_child)
|
168
|
-
@new_resource.values([{ name: "Mango", type: :string, data: "Yellow" }])
|
169
|
-
@new_resource.run_action(:create)
|
170
|
-
|
171
|
-
expect(@registry.data_exists?(reg_child, { name: "Mango", type: :string, data: "Yellow" })).to eq(true)
|
172
|
-
end
|
173
|
-
|
174
|
-
it "modifies the data if the key and value exist and type matches" do
|
175
|
-
@new_resource.key(reg_child)
|
176
|
-
@new_resource.values([{ name: "Color", type: :string, data: "Not just Orange - OpscodeOrange!" }])
|
177
|
-
@new_resource.run_action(:create)
|
178
|
-
|
179
|
-
expect(@registry.data_exists?(reg_child, { name: "Color", type: :string, data: "Not just Orange - OpscodeOrange!" })).to eq(true)
|
180
|
-
end
|
181
|
-
|
182
|
-
it "modifys the type if the key and value exist and the type does not match" do
|
183
|
-
@new_resource.key(reg_child)
|
184
|
-
@new_resource.values([{ name: "Color", type: :multi_string, data: ["Not just Orange - OpscodeOrange!"] }])
|
185
|
-
@new_resource.run_action(:create)
|
186
|
-
|
187
|
-
expect(@registry.data_exists?(reg_child, { name: "Color", type: :multi_string, data: ["Not just Orange - OpscodeOrange!"] })).to eq(true)
|
188
|
-
end
|
189
|
-
|
190
|
-
it "creates subkey if parent exists" do
|
191
|
-
@new_resource.key(reg_child + "\\OpscodeTest")
|
192
|
-
@new_resource.values([{ name: "Chef", type: :multi_string, data: %w{OpscodeOrange Rules} }])
|
193
|
-
@new_resource.recursive(false)
|
194
|
-
@new_resource.run_action(:create)
|
195
|
-
|
196
|
-
expect(@registry.key_exists?(reg_child + "\\OpscodeTest")).to eq(true)
|
197
|
-
expect(@registry.value_exists?(reg_child + "\\OpscodeTest", { name: "Chef", type: :multi_string, data: %w{OpscodeOrange Rules} })).to eq(true)
|
198
|
-
end
|
199
|
-
|
200
|
-
it "raises an error if action create and parent does not exist and recursive is set to false" do
|
201
|
-
@new_resource.key(reg_child + '\Missing1\Missing2')
|
202
|
-
@new_resource.values([{ name: "OC", type: :string, data: "MissingData" }])
|
203
|
-
@new_resource.recursive(false)
|
204
|
-
expect { @new_resource.run_action(:create) }.to raise_error(Chef::Exceptions::Win32RegNoRecursive)
|
205
|
-
end
|
206
|
-
|
207
|
-
it "raises an error if action create and type key missing in values hash" do
|
208
|
-
@new_resource.key(reg_child)
|
209
|
-
@new_resource.values([{ name: "OC", data: "my_data" }])
|
210
|
-
expect { @new_resource.run_action(:create) }.to raise_error(Chef::Exceptions::RegKeyValuesTypeMissing)
|
211
|
-
end
|
212
|
-
|
213
|
-
it "raises an error if action create and data key missing in values hash" do
|
214
|
-
@new_resource.key(reg_child)
|
215
|
-
@new_resource.values([{ name: "OC", type: :string }])
|
216
|
-
expect { @new_resource.run_action(:create) }.to raise_error(Chef::Exceptions::RegKeyValuesDataMissing)
|
217
|
-
end
|
218
|
-
|
219
|
-
it "raises an error if action create and only name key present in values hash" do
|
220
|
-
@new_resource.key(reg_child)
|
221
|
-
@new_resource.values([{ name: "OC" }])
|
222
|
-
expect { @new_resource.run_action(:create) }.to raise_error(Chef::Exceptions::RegKeyValuesTypeMissing)
|
223
|
-
end
|
224
|
-
|
225
|
-
it "does not raise an error if action create and all keys are present in values hash" do
|
226
|
-
@new_resource.key(reg_child)
|
227
|
-
@new_resource.values([{ name: "OC", type: :string, data: "my_data" }])
|
228
|
-
expect { @new_resource.run_action(:create) }.to_not raise_error
|
229
|
-
end
|
230
|
-
|
231
|
-
it "creates missing keys if action create and parent does not exist and recursive is set to true" do
|
232
|
-
@new_resource.key(reg_child + '\Missing1\Missing2')
|
233
|
-
@new_resource.values([{ name: "OC", type: :string, data: "MissingData" }])
|
234
|
-
@new_resource.recursive(true)
|
235
|
-
@new_resource.run_action(:create)
|
236
|
-
|
237
|
-
expect(@registry.key_exists?(reg_child + '\Missing1\Missing2')).to eq(true)
|
238
|
-
expect(@registry.value_exists?(reg_child + '\Missing1\Missing2', { name: "OC", type: :string, data: "MissingData" })).to eq(true)
|
239
|
-
end
|
240
|
-
|
241
|
-
it "creates key with multiple value as specified" do
|
242
|
-
@new_resource.key(reg_child)
|
243
|
-
@new_resource.values([{ name: "one", type: :string, data: "1" }, { name: "two", type: :string, data: "2" }, { name: "three", type: :string, data: "3" }])
|
244
|
-
@new_resource.recursive(true)
|
245
|
-
@new_resource.run_action(:create)
|
246
|
-
|
247
|
-
@new_resource.each_value do |value|
|
248
|
-
expect(@registry.value_exists?(reg_child, value)).to eq(true)
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
context "when running on 64-bit server", :windows64_only do
|
253
|
-
before(:all) do
|
254
|
-
reset_registry
|
255
|
-
end
|
256
|
-
after(:all) do
|
257
|
-
@new_resource.architecture(:machine)
|
258
|
-
@registry.architecture = :machine
|
259
|
-
end
|
260
|
-
it "creates a key in a 32-bit registry that is not viewable in 64-bit" do
|
261
|
-
@new_resource.key(reg_child + "\\Atraxi" )
|
262
|
-
@new_resource.values([{ name: "OC", type: :string, data: "Data" }])
|
263
|
-
@new_resource.recursive(true)
|
264
|
-
@new_resource.architecture(:i386)
|
265
|
-
@new_resource.run_action(:create)
|
266
|
-
@registry.architecture = :i386
|
267
|
-
expect(@registry.data_exists?(reg_child + "\\Atraxi", { name: "OC", type: :string, data: "Data" })).to eq(true)
|
268
|
-
@registry.architecture = :x86_64
|
269
|
-
expect(@registry.key_exists?(reg_child + "\\Atraxi")).to eq(false)
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
273
|
-
it "prepares the reporting data for action :create" do
|
274
|
-
@new_resource.key(reg_child + "\\Ood")
|
275
|
-
@new_resource.values([{ name: "ReportingVal1", type: :string, data: "report1" }, { name: "ReportingVal2", type: :string, data: "report2" }])
|
276
|
-
@new_resource.recursive(true)
|
277
|
-
@new_resource.run_action(:create)
|
278
|
-
@report = @resource_reporter.prepare_run_data
|
279
|
-
|
280
|
-
expect(@report["action"]).to eq("end")
|
281
|
-
expect(@report["resources"][0]["type"]).to eq("registry_key")
|
282
|
-
expect(@report["resources"][0]["name"]).to eq(resource_name)
|
283
|
-
expect(@report["resources"][0]["id"]).to eq(reg_child + "\\Ood")
|
284
|
-
expect(@report["resources"][0]["after"][:values]).to eq([{ name: "ReportingVal1", type: :string, data: "report1" },
|
285
|
-
{ name: "ReportingVal2", type: :string, data: "report2" }])
|
286
|
-
expect(@report["resources"][0]["before"][:values]).to eq([])
|
287
|
-
expect(@report["resources"][0]["result"]).to eq("create")
|
288
|
-
expect(@report["status"]).to eq("success")
|
289
|
-
expect(@report["total_res_count"]).to eq("1")
|
290
|
-
end
|
291
|
-
|
292
|
-
context "while running in whyrun mode" do
|
293
|
-
before(:each) do
|
294
|
-
Chef::Config[:why_run] = true
|
295
|
-
end
|
296
|
-
|
297
|
-
it "does not raise an exception if the keys do not exist but recursive is set to false" do
|
298
|
-
@new_resource.key(reg_child + "\\Slitheen\\Raxicoricofallapatorius")
|
299
|
-
@new_resource.values([{ name: "BriskWalk", type: :string, data: "is good for health" }])
|
300
|
-
@new_resource.recursive(false)
|
301
|
-
@new_resource.run_action(:create) # should not raise_error
|
302
|
-
expect(@registry.key_exists?(reg_child + "\\Slitheen")).to eq(false)
|
303
|
-
expect(@registry.key_exists?(reg_child + "\\Slitheen\\Raxicoricofallapatorius")).to eq(false)
|
304
|
-
end
|
305
|
-
|
306
|
-
it "does not create key if the action is create" do
|
307
|
-
@new_resource.key(reg_child + "\\Slitheen")
|
308
|
-
@new_resource.values([{ name: "BriskWalk", type: :string, data: "is good for health" }])
|
309
|
-
@new_resource.recursive(false)
|
310
|
-
@new_resource.run_action(:create)
|
311
|
-
expect(@registry.key_exists?(reg_child + "\\Slitheen")).to eq(false)
|
312
|
-
end
|
313
|
-
|
314
|
-
it "does not raise an exception if the action create and type key missing in values hash" do
|
315
|
-
@new_resource.key(reg_child + "\\Slitheen")
|
316
|
-
@new_resource.values([{ name: "BriskWalk", data: "my_data" }])
|
317
|
-
@new_resource.run_action(:create) # should not raise_error
|
318
|
-
expect(@registry.key_exists?(reg_child + "\\Slitheen")).to eq(false)
|
319
|
-
end
|
320
|
-
|
321
|
-
it "does not raise an exception if the action create and data key missing in values hash" do
|
322
|
-
@new_resource.key(reg_child + "\\Slitheen")
|
323
|
-
@new_resource.values([{ name: "BriskWalk", type: :string }])
|
324
|
-
@new_resource.run_action(:create) # should not raise_error
|
325
|
-
expect(@registry.key_exists?(reg_child + "\\Slitheen")).to eq(false)
|
326
|
-
end
|
327
|
-
|
328
|
-
it "does not raise an exception if the action create and only name key present in values hash" do
|
329
|
-
@new_resource.key(reg_child + "\\Slitheen")
|
330
|
-
@new_resource.values([{ name: "BriskWalk" }])
|
331
|
-
@new_resource.run_action(:create) # should not raise_error
|
332
|
-
expect(@registry.key_exists?(reg_child + "\\Slitheen")).to eq(false)
|
333
|
-
end
|
334
|
-
|
335
|
-
it "does not raise an exception if the action create and all keys are present in values hash" do
|
336
|
-
@new_resource.key(reg_child + "\\Slitheen")
|
337
|
-
@new_resource.values([{ name: "BriskWalk", type: :string, data: "my_data" }])
|
338
|
-
@new_resource.run_action(:create) # should not raise_error
|
339
|
-
expect(@registry.key_exists?(reg_child + "\\Slitheen")).to eq(false)
|
340
|
-
end
|
96
|
+
it "raise an exception because we don't have a windows registry on non-Windows" do
|
97
|
+
expect { subject }.to raise_error(Chef::Exceptions::Win32NotWindows)
|
341
98
|
end
|
342
99
|
end
|
343
100
|
|
344
|
-
context "when
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
it "does not create the key if it already exists with same value, type and data" do
|
360
|
-
@new_resource.key(reg_child)
|
361
|
-
@new_resource.values([{ name: "Color", type: :string, data: "Orange" }])
|
362
|
-
@new_resource.run_action(:create_if_missing)
|
363
|
-
|
364
|
-
expect(@registry.key_exists?(reg_child)).to eq(true)
|
365
|
-
expect(@registry.data_exists?(reg_child, { name: "Color", type: :string, data: "Orange" })).to eq(true)
|
366
|
-
end
|
367
|
-
|
368
|
-
it "creates a value if it does not exist" do
|
369
|
-
@new_resource.key(reg_child)
|
370
|
-
@new_resource.values([{ name: "Mango", type: :string, data: "Yellow" }])
|
371
|
-
@new_resource.run_action(:create_if_missing)
|
372
|
-
|
373
|
-
expect(@registry.data_exists?(reg_child, { name: "Mango", type: :string, data: "Yellow" })).to eq(true)
|
374
|
-
end
|
375
|
-
|
376
|
-
it "creates subkey if parent exists" do
|
377
|
-
@new_resource.key(reg_child + "\\Pyrovile")
|
378
|
-
@new_resource.values([{ name: "Chef", type: :multi_string, data: %w{OpscodeOrange Rules} }])
|
379
|
-
@new_resource.recursive(false)
|
380
|
-
@new_resource.run_action(:create_if_missing)
|
381
|
-
|
382
|
-
expect(@registry.key_exists?(reg_child + "\\Pyrovile")).to eq(true)
|
383
|
-
expect(@registry.value_exists?(reg_child + "\\Pyrovile", { name: "Chef", type: :multi_string, data: %w{OpscodeOrange Rules} })).to eq(true)
|
384
|
-
end
|
385
|
-
|
386
|
-
it "raises an error if action create and parent does not exist and recursive is set to false" do
|
387
|
-
@new_resource.key(reg_child + "\\Sontaran\\Sontar")
|
388
|
-
@new_resource.values([{ name: "OC", type: :string, data: "MissingData" }])
|
389
|
-
@new_resource.recursive(false)
|
390
|
-
expect { @new_resource.run_action(:create_if_missing) }.to raise_error(Chef::Exceptions::Win32RegNoRecursive)
|
391
|
-
end
|
392
|
-
|
393
|
-
it "raises an error if action create_if_missing and type key missing in values hash" do
|
394
|
-
@new_resource.key(reg_child)
|
395
|
-
@new_resource.values([{ name: "OC", data: "my_data" }])
|
396
|
-
expect { @new_resource.run_action(:create_if_missing) }.to raise_error(Chef::Exceptions::RegKeyValuesTypeMissing)
|
397
|
-
end
|
101
|
+
context "when running on Windows", :windows_only do
|
102
|
+
# this is moderately brittle, but it seems to be the order of operations
|
103
|
+
# necessary to get a report out of the resource reporter
|
104
|
+
before do
|
105
|
+
events
|
106
|
+
node
|
107
|
+
node.name(node_name)
|
108
|
+
ohai
|
109
|
+
ohai.all_plugins
|
110
|
+
node.consume_external_attrs(ohai.data, {})
|
111
|
+
run_context
|
112
|
+
action_collection
|
113
|
+
new_resource
|
114
|
+
registry
|
398
115
|
|
399
|
-
|
400
|
-
@new_resource.key(reg_child)
|
401
|
-
@new_resource.values([{ name: "OC", type: :string }])
|
402
|
-
expect { @new_resource.run_action(:create_if_missing) }.to raise_error(Chef::Exceptions::RegKeyValuesDataMissing)
|
403
|
-
end
|
404
|
-
|
405
|
-
it "raises an error if action create_if_missing and only name key present in values hash" do
|
406
|
-
@new_resource.key(reg_child)
|
407
|
-
@new_resource.values([{ name: "OC" }])
|
408
|
-
expect { @new_resource.run_action(:create_if_missing) }.to raise_error(Chef::Exceptions::RegKeyValuesTypeMissing)
|
409
|
-
end
|
410
|
-
|
411
|
-
it "does not raise an error if action create_if_missing and all keys are present in values hash" do
|
412
|
-
@new_resource.key(reg_child)
|
413
|
-
@new_resource.values([{ name: "OC", type: :string, data: "my_data" }])
|
414
|
-
expect { @new_resource.run_action(:create_if_missing) }.to_not raise_error
|
415
|
-
end
|
416
|
-
|
417
|
-
it "creates missing keys if action create and parent does not exist and recursive is set to true" do
|
418
|
-
@new_resource.key(reg_child + "\\Sontaran\\Sontar")
|
419
|
-
@new_resource.values([{ name: "OC", type: :string, data: "MissingData" }])
|
420
|
-
@new_resource.recursive(true)
|
421
|
-
@new_resource.run_action(:create_if_missing)
|
422
|
-
|
423
|
-
expect(@registry.key_exists?(reg_child + "\\Sontaran\\Sontar")).to eq(true)
|
424
|
-
expect(@registry.value_exists?(reg_child + "\\Sontaran\\Sontar", { name: "OC", type: :string, data: "MissingData" })).to eq(true)
|
425
|
-
end
|
426
|
-
|
427
|
-
it "creates key with multiple value as specified" do
|
428
|
-
@new_resource.key(reg_child + "\\Adipose")
|
429
|
-
@new_resource.values([{ name: "one", type: :string, data: "1" }, { name: "two", type: :string, data: "2" }, { name: "three", type: :string, data: "3" }])
|
430
|
-
@new_resource.recursive(true)
|
431
|
-
@new_resource.run_action(:create_if_missing)
|
432
|
-
|
433
|
-
@new_resource.each_value do |value|
|
434
|
-
expect(@registry.value_exists?(reg_child + "\\Adipose", value)).to eq(true)
|
435
|
-
end
|
436
|
-
end
|
437
|
-
|
438
|
-
it "prepares the reporting data for :create_if_missing" do
|
439
|
-
@new_resource.key(reg_child + "\\Judoon")
|
440
|
-
@new_resource.values([{ name: "ReportingVal3", type: :string, data: "report3" }])
|
441
|
-
@new_resource.recursive(true)
|
442
|
-
@new_resource.run_action(:create_if_missing)
|
443
|
-
@report = @resource_reporter.prepare_run_data
|
444
|
-
|
445
|
-
expect(@report["action"]).to eq("end")
|
446
|
-
expect(@report["resources"][0]["type"]).to eq("registry_key")
|
447
|
-
expect(@report["resources"][0]["name"]).to eq(resource_name)
|
448
|
-
expect(@report["resources"][0]["id"]).to eq(reg_child + "\\Judoon")
|
449
|
-
expect(@report["resources"][0]["after"][:values]).to eq([{ name: "ReportingVal3", type: :string, data: "report3" }])
|
450
|
-
expect(@report["resources"][0]["before"][:values]).to eq([])
|
451
|
-
expect(@report["resources"][0]["result"]).to eq("create_if_missing")
|
452
|
-
expect(@report["status"]).to eq("success")
|
453
|
-
expect(@report["total_res_count"]).to eq("1")
|
116
|
+
reset_registry
|
454
117
|
end
|
455
118
|
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
119
|
+
after do
|
120
|
+
clean_registry
|
121
|
+
end
|
122
|
+
subject do
|
123
|
+
resource_reporter
|
124
|
+
events.register(resource_reporter)
|
125
|
+
events.register(action_collection)
|
126
|
+
resource_reporter.action_collection_registration(action_collection)
|
127
|
+
resource_reporter.run_started(run_status)
|
128
|
+
new_resource.key(registry_key)
|
129
|
+
new_resource.values(registry_key_values)
|
130
|
+
new_resource.run_action(action)
|
131
|
+
end
|
132
|
+
|
133
|
+
context "action :create" do
|
134
|
+
let(:action) { :create }
|
135
|
+
let(:registry_key_values) { [{ name: "Color", type: :string, data: "Orange" }] }
|
136
|
+
let(:registry_key) { reg_child }
|
137
|
+
before { reset_registry }
|
138
|
+
it "creates a registry key if the key is missing" do
|
139
|
+
subject
|
140
|
+
expect(registry.key_exists?(registry_key)).to be true
|
141
|
+
expect(registry.get_values(registry_key)).to eq(registry_key_values)
|
142
|
+
report = resource_reporter.prepare_run_data
|
143
|
+
expect(report["resources"][0]["after"][:values]).to eq(registry_key_values)
|
468
144
|
end
|
469
145
|
|
470
|
-
it "does
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
146
|
+
it "does not create a registry key if it already exists" do
|
147
|
+
registry.create_key(registry_key, true)
|
148
|
+
registry_key_values.each do |rkv|
|
149
|
+
registry.set_value(registry_key, rkv)
|
150
|
+
end
|
151
|
+
subject
|
152
|
+
report = resource_reporter.prepare_run_data
|
153
|
+
expect(report["total_res_count"]).to eq("0")
|
476
154
|
end
|
477
155
|
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
156
|
+
let(:prepopulated_values) do
|
157
|
+
[
|
158
|
+
{ name: "TheBefore", type: :multi_string, data: %w{abc def} },
|
159
|
+
{ name: "ReportingVal1", type: :dword, data: 1234 },
|
160
|
+
]
|
483
161
|
end
|
484
162
|
|
485
|
-
|
486
|
-
|
487
|
-
@new_resource.values([{ name: "BriskWalk", type: :string }])
|
488
|
-
@new_resource.run_action(:create_if_missing) # should not raise_error
|
489
|
-
expect(@registry.key_exists?(reg_child + "\\Zygons")).to eq(false)
|
490
|
-
end
|
163
|
+
def prepopulate(key, values)
|
164
|
+
registry.create_key(key, true)
|
491
165
|
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
@new_resource.run_action(:create_if_missing) # should not raise_error
|
496
|
-
expect(@registry.key_exists?(reg_child + "\\Zygons")).to eq(false)
|
166
|
+
values.each do |value|
|
167
|
+
registry.set_value(registry_key, value)
|
168
|
+
end
|
497
169
|
end
|
498
170
|
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
expect(@registry.key_exists?(reg_child + "\\Zygons")).to eq(false)
|
504
|
-
end
|
505
|
-
end
|
506
|
-
end
|
507
|
-
|
508
|
-
context "when the action is delete" do
|
509
|
-
before(:all) do
|
510
|
-
reset_registry
|
511
|
-
create_deletable_keys
|
512
|
-
end
|
513
|
-
|
514
|
-
it "takes no action if the specified key path does not exist in the system" do
|
515
|
-
expect(@registry.key_exists?(reg_parent + "\\Osirian")).to eq(false)
|
516
|
-
|
517
|
-
@new_resource.key(reg_parent + "\\Osirian")
|
518
|
-
@new_resource.recursive(false)
|
519
|
-
@new_resource.run_action(:delete)
|
520
|
-
|
521
|
-
expect(@registry.key_exists?(reg_parent + "\\Osirian")).to eq(false)
|
522
|
-
end
|
523
|
-
|
524
|
-
it "takes no action if the key exists but the value does not" do
|
525
|
-
expect(@registry.data_exists?(reg_parent + "\\Opscode", { name: "Color", type: :string, data: "Orange" })).to eq(true)
|
526
|
-
|
527
|
-
@new_resource.key(reg_parent + "\\Opscode")
|
528
|
-
@new_resource.values([{ name: "LooksLike", type: :multi_string, data: %w{SeattleGrey OCOrange} }])
|
529
|
-
@new_resource.recursive(false)
|
530
|
-
@new_resource.run_action(:delete)
|
531
|
-
|
532
|
-
expect(@registry.data_exists?(reg_parent + "\\Opscode", { name: "Color", type: :string, data: "Orange" })).to eq(true)
|
533
|
-
end
|
171
|
+
describe "new key" do
|
172
|
+
before { new_resource.recursive(true) }
|
173
|
+
let(:registry_key) { "#{reg_child}\\NewValues" }
|
174
|
+
let(:registry_key_values) { [{ name: "SomeValue", type: :string, data: "Blue" }] }
|
534
175
|
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
expect(@registry.data_exists?(reg_parent + "\\Opscode", { name: "Color", type: :string, data: "Orange" })).to eq(true)
|
542
|
-
expect(@registry.value_exists?(reg_parent + "\\Opscode", { name: "AKA", type: :string, data: "OC" })).to eq(false)
|
543
|
-
expect(@registry.value_exists?(reg_parent + "\\Opscode", { name: "Opscode", type: :multi_string, data: %w{Seattle Washington} })).to eq(false)
|
544
|
-
end
|
545
|
-
|
546
|
-
it "it deletes the values with the same name irrespective of it type and data" do
|
547
|
-
@new_resource.key(reg_parent + "\\Opscode")
|
548
|
-
@new_resource.values([{ name: "Color", type: :multi_string, data: %w{Black Orange} }])
|
549
|
-
@new_resource.recursive(false)
|
550
|
-
@new_resource.run_action(:delete)
|
551
|
-
|
552
|
-
expect(@registry.value_exists?(reg_parent + "\\Opscode", { name: "Color", type: :string, data: "Orange" })).to eq(false)
|
553
|
-
end
|
554
|
-
|
555
|
-
it "prepares the reporting data for action :delete" do
|
556
|
-
@new_resource.key(reg_parent + "\\ReportKey")
|
557
|
-
@new_resource.values([{ name: "ReportVal4", type: :string, data: "report4" }, { name: "ReportVal5", type: :string, data: "report5" }])
|
558
|
-
@new_resource.recursive(true)
|
559
|
-
@new_resource.run_action(:delete)
|
560
|
-
|
561
|
-
@report = @resource_reporter.prepare_run_data
|
562
|
-
|
563
|
-
expect(@registry.value_exists?(reg_parent + "\\ReportKey", [{ name: "ReportVal4", type: :string, data: "report4" }, { name: "ReportVal5", type: :string, data: "report5" }])).to eq(false)
|
564
|
-
|
565
|
-
expect(@report["action"]).to eq("end")
|
566
|
-
expect(@report["resources"].count).to eq(1)
|
567
|
-
expect(@report["resources"][0]["type"]).to eq("registry_key")
|
568
|
-
expect(@report["resources"][0]["name"]).to eq(resource_name)
|
569
|
-
expect(@report["resources"][0]["id"]).to eq(reg_parent + "\\ReportKey")
|
570
|
-
expect(@report["resources"][0]["before"][:values]).to eq([{ name: "ReportVal4", type: :string, data: "report4" },
|
571
|
-
{ name: "ReportVal5", type: :string, data: "report5" }])
|
572
|
-
# Not testing for after values to match since after -> new_resource values.
|
573
|
-
expect(@report["resources"][0]["result"]).to eq("delete")
|
574
|
-
expect(@report["status"]).to eq("success")
|
575
|
-
expect(@report["total_res_count"]).to eq("1")
|
576
|
-
end
|
577
|
-
|
578
|
-
context "while running in whyrun mode" do
|
579
|
-
before(:each) do
|
580
|
-
Chef::Config[:why_run] = true
|
176
|
+
it "creates the new registry key with the specified values" do
|
177
|
+
subject
|
178
|
+
expect(registry.key_exists?(registry_key)).to be true
|
179
|
+
expect(registry.value_exists?(registry_key, registry_key_values[-1])).to be true
|
180
|
+
end
|
581
181
|
end
|
582
|
-
it "does nothing if the action is delete" do
|
583
|
-
@new_resource.key(reg_parent + "\\OpscodeWhyRun")
|
584
|
-
@new_resource.values([{ name: "BriskWalk", type: :string, data: "is good for health" }])
|
585
|
-
@new_resource.recursive(false)
|
586
|
-
@new_resource.run_action(:delete)
|
587
182
|
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
183
|
+
context "an existing key" do
|
184
|
+
let(:registry_key) { "#{reg_child}\\ExistingValue" }
|
185
|
+
let(:initial_values) { [{ name: "SomeValue", type: :dword, data: 3321 }] }
|
186
|
+
|
187
|
+
before do
|
188
|
+
prepopulate(registry_key, initial_values)
|
189
|
+
end
|
190
|
+
|
191
|
+
context "same value, type, and data" do
|
192
|
+
let(:registry_key_values) { initial_values }
|
193
|
+
|
194
|
+
it "doesn't update the key if the values are the same" do
|
195
|
+
subject
|
196
|
+
expect(new_resource).not_to be_updated_by_last_action
|
197
|
+
expect(registry.key_exists?(registry_key)).to be true
|
198
|
+
expect(registry.value_exists?(registry_key, initial_values[-1])).to be true
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
context "same value, type, but datatype of data differs" do
|
203
|
+
let(:registry_key_values) { [{ name: "SomeValue", type: :dword, data: "3321" }] }
|
204
|
+
|
205
|
+
it "updates the key if the value type is different" do
|
206
|
+
subject
|
207
|
+
expect(new_resource).not_to be_updated_by_last_action
|
208
|
+
expect(registry.key_exists?(registry_key)).to be true
|
209
|
+
expect(registry.value_exists?(registry_key, initial_values[-1])).to be true
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
context "same value, different type, data type differs" do
|
214
|
+
let(:registry_key_values) { [{ name: "SomeValue", type: :multi_string, data: %w{3321 2231} }] }
|
215
|
+
|
216
|
+
it "updates the key if the value type is different" do
|
217
|
+
subject
|
218
|
+
expect(new_resource).to be_updated_by_last_action
|
219
|
+
expect(registry.key_exists?(registry_key)).to be true
|
220
|
+
expect(registry.value_exists?(registry_key, registry_key_values[-1])).to be true
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
context "parent exists, but not child" do
|
225
|
+
let(:registry_key) { "#{reg_child}\\DoesNotExist" }
|
226
|
+
before { new_resource.recursive(false) }
|
227
|
+
it "creates the child if the parent exists" do
|
228
|
+
subject
|
229
|
+
expect(registry.key_exists?(registry_key)).to eq(true)
|
230
|
+
expect(registry.value_exists?(registry_key, registry_key_values[-1])).to be true
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
context "missing type key" do
|
235
|
+
let(:registry_key) { "#{reg_child}\\MissingTypeKey" }
|
236
|
+
let(:registry_key_values) { [{ name: "SomeValue", data: "3321" }] }
|
237
|
+
it "raises RegKeyValuesTypeMissing" do
|
238
|
+
expect { subject }.to raise_error(Chef::Exceptions::RegKeyValuesTypeMissing)
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
context "missing data key" do
|
243
|
+
let(:registry_key) { "#{reg_child}\\MissingDataKey" }
|
244
|
+
let(:registry_key_values) { [{ name: "SomeValue", type: :string }] }
|
245
|
+
it "raises RegKeyValuesTypeMissing" do
|
246
|
+
expect { subject }.to raise_error(Chef::Exceptions::RegKeyValuesDataMissing)
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
context "new value" do
|
251
|
+
let(:registry_key_values) { [{ name: "NewValue", type: :string, data: "Green" }] }
|
252
|
+
|
253
|
+
it "creates a value if it does not exist" do
|
254
|
+
subject
|
255
|
+
expect(new_resource).to be_updated_by_last_action
|
256
|
+
expect(registry.key_exists?(registry_key)).to be true
|
257
|
+
expect(registry.value_exists?(registry_key, registry_key_values[-1])).to be true
|
258
|
+
end
|
259
|
+
end
|
658
260
|
end
|
659
261
|
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
262
|
+
context "two deep" do
|
263
|
+
let(:registry_key) { "#{reg_child}\\#{rand(1000..2000)}\\#{rand(1000..3000)}}" }
|
264
|
+
context "recursive true" do
|
265
|
+
before { new_resource.recursive(true) }
|
266
|
+
it "creates the child" do
|
267
|
+
subject
|
268
|
+
expect(registry.key_exists?(registry_key)).to eq(true)
|
269
|
+
expect(registry.value_exists?(registry_key, registry_key_values[-1])).to be true
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
context "recursive false" do
|
274
|
+
before { new_resource.recursive(false) }
|
275
|
+
it "raises Win32RegNoRecursive" do
|
276
|
+
expect { subject }.to raise_error(Chef::Exceptions::Win32RegNoRecursive)
|
277
|
+
end
|
278
|
+
end
|
665
279
|
end
|
666
|
-
it "does nothing if the action is delete_key" do
|
667
|
-
@new_resource.key(reg_parent + "\\OpscodeWhyRun")
|
668
|
-
@new_resource.values([{ name: "BriskWalk", type: :string, data: "is good for health" }])
|
669
|
-
@new_resource.recursive(false)
|
670
|
-
@new_resource.run_action(:delete_key)
|
671
280
|
|
672
|
-
|
281
|
+
context "create key with multiple values" do
|
282
|
+
before { new_resource.recursive(true) }
|
283
|
+
let(:registry_key) { "#{reg_child}\\MultipleValueKey" }
|
284
|
+
let(:registry_key_values) do
|
285
|
+
[
|
286
|
+
{ name: "SomeValue", type: :string, data: "Blue" },
|
287
|
+
{ name: "AnotherValue", type: :string, data: "Green" },
|
288
|
+
]
|
289
|
+
end
|
290
|
+
it "creates all the values" do
|
291
|
+
subject
|
292
|
+
expect(registry.key_exists?(registry_key)).to eq(true)
|
293
|
+
registry_key_values.each do |value|
|
294
|
+
expect(registry.value_exists?(registry_key, value)).to be true
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
context "when only_record_changes is the default (true)" do
|
299
|
+
before do
|
300
|
+
prepopulate(registry_key, prepopulated_values)
|
301
|
+
end
|
302
|
+
let(:registry_key) { "#{reg_child}\\OnlyRecordChanges" }
|
303
|
+
let(:registry_key_values) { [{ name: "ReportingVal1", type: :string, data: rand(1235..10000) }] }
|
304
|
+
|
305
|
+
it "should only report the changed value" do
|
306
|
+
subject
|
307
|
+
report = resource_reporter.prepare_run_data
|
308
|
+
|
309
|
+
expect(report["action"]).to eq("end")
|
310
|
+
expect(report["resources"][0]["type"]).to eq(:registry_key)
|
311
|
+
expect(report["resources"][0]["name"]).to eq(resource_name)
|
312
|
+
expect(report["resources"][0]["id"]).to eq(registry_key)
|
313
|
+
expect(report["resources"][0]["after"][:values]).to eq(registry_key_values)
|
314
|
+
expect(report["resources"][0]["before"][:values]).to eq(prepopulated_values.select { |ppv| ppv[:name] == "ReportingVal1" })
|
315
|
+
expect(report["resources"][0]["result"]).to eq("create")
|
316
|
+
expect(report["status"]).to eq("success")
|
317
|
+
expect(report["total_res_count"]).to eq("1")
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
context "when only_record_changes is false" do
|
322
|
+
before do
|
323
|
+
new_resource.only_record_changes(false)
|
324
|
+
prepopulate(registry_key, prepopulated_values)
|
325
|
+
end
|
326
|
+
let(:registry_key) { "#{reg_child}\\RecordItAll" }
|
327
|
+
let(:registry_key_values) { [{ name: "ReportingVal1", type: :string, data: rand(1235..10000) }] }
|
328
|
+
|
329
|
+
it "should only report the changed value" do
|
330
|
+
subject
|
331
|
+
report = resource_reporter.prepare_run_data
|
332
|
+
|
333
|
+
expect(report["resources"][0]["after"][:values]).to eq(registry_key_values)
|
334
|
+
expect(report["resources"][0]["before"][:values]).to eq(prepopulated_values)
|
335
|
+
expect(report["status"]).to eq("success")
|
336
|
+
expect(report["total_res_count"]).to eq("1")
|
337
|
+
end
|
338
|
+
|
339
|
+
end
|
673
340
|
end
|
674
341
|
end
|
675
342
|
end
|