microwave 1.0.4 → 11.400.2

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.
Files changed (249) hide show
  1. data/CONTRIBUTING.md +155 -0
  2. data/README.md +89 -0
  3. data/Rakefile +2 -2
  4. data/bin/chef-apply +25 -0
  5. data/bin/chef-shell +34 -0
  6. data/bin/chef-solo +0 -2
  7. data/bin/shef +6 -5
  8. data/lib/chef.rb +2 -4
  9. data/spec/data/big_json.json +2 -1
  10. data/spec/data/big_json_plus_one.json +2 -1
  11. data/spec/data/cookbooks/chefignore +2 -0
  12. data/spec/data/cookbooks/openldap/attributes/default.rb +10 -9
  13. data/spec/data/cookbooks/openldap/attributes/smokey.rb +1 -1
  14. data/spec/data/git_bundles/sinatra-test-app-with-callback-files.gitbundle +0 -0
  15. data/spec/data/git_bundles/sinatra-test-app-with-symlinks.gitbundle +0 -0
  16. data/spec/data/git_bundles/sinatra-test-app.gitbundle +0 -0
  17. data/spec/data/lwrp/providers/inline_compiler.rb +26 -0
  18. data/spec/data/nodes/default.rb +3 -3
  19. data/spec/data/nodes/test.example.com.rb +3 -3
  20. data/spec/data/nodes/test.rb +3 -3
  21. data/spec/data/partial_one.erb +1 -0
  22. data/spec/data/run_context/cookbooks/circular-dep1/attributes/default.rb +4 -0
  23. data/spec/data/run_context/cookbooks/circular-dep1/definitions/circular_dep1_res.rb +1 -0
  24. data/spec/data/run_context/cookbooks/circular-dep1/libraries/lib.rb +2 -0
  25. data/spec/data/run_context/cookbooks/circular-dep1/metadata.rb +2 -0
  26. data/spec/data/run_context/cookbooks/circular-dep1/providers/provider.rb +1 -0
  27. data/spec/data/run_context/cookbooks/circular-dep1/recipes/default.rb +0 -0
  28. data/spec/data/run_context/cookbooks/circular-dep1/resources/resource.rb +1 -0
  29. data/spec/data/run_context/cookbooks/circular-dep2/attributes/default.rb +3 -0
  30. data/spec/data/run_context/cookbooks/circular-dep2/definitions/circular_dep2_res.rb +1 -0
  31. data/spec/data/run_context/cookbooks/circular-dep2/libraries/lib.rb +2 -0
  32. data/spec/data/run_context/cookbooks/circular-dep2/metadata.rb +2 -0
  33. data/spec/data/run_context/cookbooks/circular-dep2/providers/provider.rb +1 -0
  34. data/spec/data/run_context/cookbooks/circular-dep2/recipes/default.rb +0 -0
  35. data/spec/data/run_context/cookbooks/circular-dep2/resources/resource.rb +1 -0
  36. data/spec/data/run_context/cookbooks/dependency1/attributes/aa_first.rb +2 -0
  37. data/spec/data/run_context/cookbooks/dependency1/attributes/default.rb +2 -0
  38. data/spec/data/run_context/cookbooks/dependency1/attributes/zz_last.rb +3 -0
  39. data/spec/data/run_context/cookbooks/dependency1/definitions/dependency1_res.rb +1 -0
  40. data/spec/data/run_context/cookbooks/dependency1/libraries/lib.rb +2 -0
  41. data/spec/data/run_context/cookbooks/dependency1/providers/provider.rb +1 -0
  42. data/spec/data/run_context/cookbooks/dependency1/recipes/default.rb +0 -0
  43. data/spec/data/run_context/cookbooks/dependency1/resources/resource.rb +1 -0
  44. data/spec/data/run_context/cookbooks/dependency2/attributes/default.rb +3 -0
  45. data/spec/data/run_context/cookbooks/dependency2/definitions/dependency2_res.rb +1 -0
  46. data/spec/data/run_context/cookbooks/dependency2/libraries/lib.rb +2 -0
  47. data/spec/data/run_context/cookbooks/dependency2/providers/provider.rb +1 -0
  48. data/spec/data/run_context/cookbooks/dependency2/recipes/default.rb +0 -0
  49. data/spec/data/run_context/cookbooks/dependency2/resources/resource.rb +1 -0
  50. data/spec/data/run_context/cookbooks/no-default-attr/attributes/server.rb +3 -0
  51. data/spec/data/run_context/cookbooks/no-default-attr/definitions/no_default-attr_res.rb +1 -0
  52. data/spec/data/run_context/cookbooks/no-default-attr/providers/provider.rb +1 -0
  53. data/spec/data/run_context/cookbooks/no-default-attr/recipes/default.rb +0 -0
  54. data/spec/data/run_context/cookbooks/no-default-attr/resources/resource.rb +1 -0
  55. data/spec/data/run_context/cookbooks/test-with-circular-deps/attributes/default.rb +3 -0
  56. data/spec/data/run_context/cookbooks/test-with-circular-deps/definitions/test_with-circular-deps_res.rb +1 -0
  57. data/spec/data/run_context/cookbooks/test-with-circular-deps/libraries/lib.rb +2 -0
  58. data/spec/data/run_context/cookbooks/test-with-circular-deps/metadata.rb +2 -0
  59. data/spec/data/run_context/cookbooks/test-with-circular-deps/providers/provider.rb +1 -0
  60. data/spec/data/run_context/cookbooks/test-with-circular-deps/recipes/default.rb +0 -0
  61. data/spec/data/run_context/cookbooks/test-with-circular-deps/resources/resource.rb +1 -0
  62. data/spec/data/run_context/cookbooks/test-with-deps/attributes/default.rb +3 -0
  63. data/spec/data/run_context/cookbooks/test-with-deps/definitions/test_with-deps_res.rb +1 -0
  64. data/spec/data/run_context/cookbooks/test-with-deps/libraries/lib.rb +1 -0
  65. data/spec/data/run_context/cookbooks/test-with-deps/metadata.rb +3 -0
  66. data/spec/data/run_context/cookbooks/test-with-deps/providers/provider.rb +1 -0
  67. data/spec/data/run_context/cookbooks/test-with-deps/recipes/default.rb +0 -0
  68. data/spec/data/run_context/cookbooks/test-with-deps/recipes/server.rb +0 -0
  69. data/spec/data/run_context/cookbooks/test-with-deps/resources/resource.rb +1 -0
  70. data/spec/data/run_context/cookbooks/test/attributes/default.rb +0 -0
  71. data/spec/data/run_context/cookbooks/test/attributes/george.rb +1 -1
  72. data/spec/data/run_context/cookbooks/test/definitions/test_res.rb +1 -0
  73. data/spec/data/run_context/cookbooks/test/providers/provider.rb +1 -0
  74. data/spec/data/run_context/cookbooks/test/resources/resource.rb +1 -0
  75. data/spec/data/shef-config.rb +10 -0
  76. data/spec/functional/dsl/registry_helper_spec.rb +63 -0
  77. data/spec/functional/knife/cookbook_delete_spec.rb +0 -2
  78. data/spec/functional/knife/exec_spec.rb +4 -6
  79. data/spec/functional/knife/smoke_test.rb +34 -0
  80. data/spec/functional/knife/ssh_spec.rb +64 -3
  81. data/spec/functional/resource/cookbook_file_spec.rb +33 -2
  82. data/spec/functional/resource/deploy_revision_spec.rb +515 -0
  83. data/spec/functional/resource/directory_spec.rb +4 -0
  84. data/spec/functional/resource/file_spec.rb +56 -22
  85. data/spec/functional/resource/link_spec.rb +12 -10
  86. data/spec/functional/resource/registry_spec.rb +572 -0
  87. data/spec/functional/resource/remote_directory_spec.rb +142 -36
  88. data/spec/functional/resource/remote_file_spec.rb +28 -3
  89. data/spec/functional/resource/template_spec.rb +23 -2
  90. data/spec/functional/run_lock_spec.rb +238 -0
  91. data/spec/functional/shell_spec.rb +101 -0
  92. data/spec/functional/tiny_server_spec.rb +5 -4
  93. data/spec/functional/win32/registry_helper_spec.rb +632 -0
  94. data/spec/functional/win32/security_spec.rb +37 -0
  95. data/spec/spec_helper.rb +15 -3
  96. data/spec/stress/win32/security_spec.rb +5 -5
  97. data/spec/support/chef_helpers.rb +14 -3
  98. data/spec/support/lib/chef/resource/cat.rb +3 -5
  99. data/spec/support/lib/chef/resource/one_two_three_four.rb +8 -10
  100. data/spec/support/lib/chef/resource/zen_master.rb +8 -10
  101. data/spec/support/matchers/leak.rb +1 -1
  102. data/spec/support/platform_helpers.rb +18 -0
  103. data/spec/support/shared/functional/directory_resource.rb +85 -23
  104. data/spec/support/shared/functional/file_resource.rb +198 -53
  105. data/spec/support/shared/functional/securable_resource.rb +140 -105
  106. data/spec/support/shared/functional/securable_resource_with_reporting.rb +375 -0
  107. data/spec/support/shared/unit/file_system_support.rb +110 -0
  108. data/spec/support/shared/unit/platform_introspector.rb +162 -0
  109. data/spec/tiny_server.rb +29 -10
  110. data/spec/unit/api_client/registration_spec.rb +172 -0
  111. data/spec/unit/api_client_spec.rb +156 -103
  112. data/spec/unit/application/apply.rb +84 -0
  113. data/spec/unit/application/knife_spec.rb +5 -0
  114. data/spec/unit/application_spec.rb +57 -2
  115. data/spec/unit/chef_fs/diff_spec.rb +329 -0
  116. data/spec/unit/chef_fs/file_pattern_spec.rb +526 -0
  117. data/spec/unit/chef_fs/file_system/chef_server_root_dir_spec.rb +237 -0
  118. data/spec/unit/chef_fs/file_system/cookbooks_dir_spec.rb +568 -0
  119. data/spec/unit/chef_fs/file_system/data_bags_dir_spec.rb +220 -0
  120. data/spec/unit/chef_fs/file_system_spec.rb +136 -0
  121. data/spec/unit/client_spec.rb +188 -16
  122. data/spec/unit/config_spec.rb +54 -4
  123. data/spec/unit/cookbook/chefignore_spec.rb +2 -1
  124. data/spec/unit/cookbook/syntax_check_spec.rb +48 -109
  125. data/spec/unit/cookbook_loader_spec.rb +153 -91
  126. data/spec/unit/cookbook_manifest_spec.rb +81 -81
  127. data/spec/unit/cookbook_spec.rb +3 -20
  128. data/spec/unit/cookbook_version_spec.rb +23 -122
  129. data/spec/unit/digester_spec.rb +50 -0
  130. data/spec/unit/dsl/data_query_spec.rb +66 -0
  131. data/spec/unit/dsl/platform_introspection_spec.rb +130 -0
  132. data/spec/unit/dsl/regsitry_helper_spec.rb +55 -0
  133. data/spec/unit/encrypted_data_bag_item_spec.rb +126 -10
  134. data/spec/unit/environment_spec.rb +0 -130
  135. data/spec/unit/exceptions_spec.rb +2 -3
  136. data/spec/unit/formatters/error_inspectors/resource_failure_inspector_spec.rb +23 -3
  137. data/spec/unit/json_compat_spec.rb +69 -0
  138. data/spec/unit/knife/bootstrap_spec.rb +81 -28
  139. data/spec/unit/knife/client_reregister_spec.rb +23 -22
  140. data/spec/unit/knife/configure_spec.rb +29 -26
  141. data/spec/unit/knife/cookbook_metadata_spec.rb +11 -4
  142. data/spec/unit/knife/cookbook_site_install_spec.rb +12 -2
  143. data/spec/unit/knife/cookbook_test_spec.rb +1 -0
  144. data/spec/unit/knife/cookbook_upload_spec.rb +41 -2
  145. data/spec/unit/knife/core/bootstrap_context_spec.rb +8 -1
  146. data/spec/unit/knife/core/ui_spec.rb +156 -7
  147. data/spec/unit/knife/data_bag_create_spec.rb +14 -0
  148. data/spec/unit/knife/data_bag_edit_spec.rb +14 -4
  149. data/spec/unit/knife/data_bag_from_file_spec.rb +17 -5
  150. data/spec/unit/knife/data_bag_show_spec.rb +11 -4
  151. data/spec/unit/knife/index_rebuild_spec.rb +96 -33
  152. data/spec/unit/knife/knife_help.rb +7 -7
  153. data/spec/unit/knife/node_run_list_remove_spec.rb +2 -1
  154. data/spec/unit/knife/ssh_spec.rb +121 -15
  155. data/spec/unit/knife/status_spec.rb +2 -2
  156. data/spec/unit/knife/user_create_spec.rb +86 -0
  157. data/spec/unit/knife/user_delete_spec.rb +39 -0
  158. data/spec/unit/knife/user_edit_spec.rb +42 -0
  159. data/spec/unit/knife/user_list_spec.rb +32 -0
  160. data/spec/unit/knife/user_reregister_spec.rb +53 -0
  161. data/spec/unit/knife/user_show_spec.rb +41 -0
  162. data/spec/unit/knife_spec.rb +53 -0
  163. data/spec/unit/lwrp_spec.rb +59 -17
  164. data/spec/unit/mixin/checksum_spec.rb +2 -2
  165. data/spec/unit/mixin/deep_merge_spec.rb +56 -491
  166. data/spec/unit/mixin/deprecation_spec.rb +23 -0
  167. data/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +6 -1
  168. data/spec/unit/mixin/params_validate_spec.rb +4 -2
  169. data/spec/unit/mixin/securable_spec.rb +5 -3
  170. data/spec/unit/mixin/template_spec.rb +119 -0
  171. data/spec/unit/node/attribute_spec.rb +272 -137
  172. data/spec/unit/node/immutable_collections_spec.rb +139 -0
  173. data/spec/unit/node_spec.rb +411 -339
  174. data/spec/unit/platform_spec.rb +8 -8
  175. data/spec/unit/provider/breakpoint_spec.rb +8 -8
  176. data/spec/unit/provider/cookbook_file_spec.rb +4 -8
  177. data/spec/unit/provider/deploy/revision_spec.rb +2 -8
  178. data/spec/unit/provider/deploy_spec.rb +6 -40
  179. data/spec/unit/provider/directory_spec.rb +103 -68
  180. data/spec/unit/provider/erl_call_spec.rb +0 -2
  181. data/spec/unit/provider/file_spec.rb +69 -59
  182. data/spec/unit/provider/git_spec.rb +0 -10
  183. data/spec/unit/provider/group/groupadd_spec.rb +1 -1
  184. data/spec/unit/provider/group/usermod_spec.rb +2 -2
  185. data/spec/unit/provider/http_request_spec.rb +28 -69
  186. data/spec/unit/provider/ifconfig_spec.rb +2 -2
  187. data/spec/unit/provider/link_spec.rb +1 -1
  188. data/spec/unit/provider/ohai_spec.rb +4 -4
  189. data/spec/unit/provider/package/apt_spec.rb +0 -1
  190. data/spec/unit/provider/package/ips_spec.rb +0 -1
  191. data/spec/unit/provider/package/rubygems_spec.rb +0 -18
  192. data/spec/unit/provider/package/yum_spec.rb +79 -15
  193. data/spec/unit/provider/package_spec.rb +7 -5
  194. data/spec/unit/provider/registry_key_spec.rb +269 -0
  195. data/spec/unit/provider/remote_directory_spec.rb +24 -7
  196. data/spec/unit/provider/remote_file_spec.rb +36 -0
  197. data/spec/unit/provider/route_spec.rb +3 -6
  198. data/spec/unit/provider/ruby_block_spec.rb +8 -0
  199. data/spec/unit/provider/service/arch_service_spec.rb +4 -4
  200. data/spec/unit/provider/service/debian_service_spec.rb +1 -1
  201. data/spec/unit/provider/service/freebsd_service_spec.rb +4 -4
  202. data/spec/unit/provider/service/init_service_spec.rb +26 -3
  203. data/spec/unit/provider/service/insserv_service_spec.rb +1 -1
  204. data/spec/unit/provider/service/invokercd_service_spec.rb +3 -3
  205. data/spec/unit/provider/service/redhat_spec.rb +1 -1
  206. data/spec/unit/provider/service/simple_service_spec.rb +3 -3
  207. data/spec/unit/provider/service/upstart_service_spec.rb +7 -7
  208. data/spec/unit/provider/service_spec.rb +2 -2
  209. data/spec/unit/provider/subversion_spec.rb +1 -1
  210. data/spec/unit/provider/template_spec.rb +35 -11
  211. data/spec/unit/provider/user/dscl_spec.rb +57 -31
  212. data/spec/unit/provider/user_spec.rb +7 -16
  213. data/spec/unit/provider_spec.rb +4 -3
  214. data/spec/unit/recipe_spec.rb +10 -8
  215. data/spec/unit/registry_helper_spec.rb +376 -0
  216. data/spec/unit/resource/log_spec.rb +9 -0
  217. data/spec/unit/resource/registry_key_spec.rb +171 -0
  218. data/spec/unit/resource/remote_file_spec.rb +21 -23
  219. data/spec/unit/resource/ruby_block_spec.rb +7 -3
  220. data/spec/unit/resource/service_spec.rb +11 -0
  221. data/spec/unit/resource_spec.rb +27 -4
  222. data/spec/unit/rest/auth_credentials_spec.rb +2 -14
  223. data/spec/unit/rest_spec.rb +122 -187
  224. data/spec/unit/run_context/cookbook_compiler_spec.rb +181 -0
  225. data/spec/unit/run_context_spec.rb +18 -4
  226. data/spec/unit/run_list_spec.rb +0 -209
  227. data/spec/unit/run_lock_spec.rb +37 -0
  228. data/spec/unit/runner_spec.rb +101 -2
  229. data/spec/unit/scan_access_control_spec.rb +4 -4
  230. data/spec/unit/{shef → shell}/model_wrapper_spec.rb +5 -5
  231. data/spec/unit/{shef/shef_ext_spec.rb → shell/shell_ext_spec.rb} +21 -21
  232. data/spec/unit/{shef/shef_session_spec.rb → shell/shell_session_spec.rb} +12 -12
  233. data/spec/unit/shell_out_spec.rb +18 -0
  234. data/spec/unit/{shef_spec.rb → shell_spec.rb} +20 -20
  235. data/spec/unit/user_spec.rb +255 -0
  236. metadata +162 -157
  237. data/README.rdoc +0 -177
  238. data/spec/unit/certificate_spec.rb +0 -76
  239. data/spec/unit/checksum_cache_spec.rb +0 -209
  240. data/spec/unit/checksum_spec.rb +0 -94
  241. data/spec/unit/couchdb_spec.rb +0 -274
  242. data/spec/unit/index_queue_spec.rb +0 -391
  243. data/spec/unit/json_compat_spect.rb +0 -53
  244. data/spec/unit/mixin/language_spec.rb +0 -305
  245. data/spec/unit/openid_registration_spec.rb +0 -153
  246. data/spec/unit/solr_query/query_transform_spec.rb +0 -454
  247. data/spec/unit/solr_query/solr_http_request_spec.rb +0 -244
  248. data/spec/unit/solr_query_spec.rb +0 -203
  249. data/spec/unit/webui_user_spec.rb +0 -238
@@ -23,6 +23,8 @@ describe Chef::Resource::Directory do
23
23
 
24
24
  let(:directory_base) { "directory_spec" }
25
25
 
26
+ let(:default_mode) { "755" }
27
+
26
28
  def create_resource
27
29
  events = Chef::EventDispatch::Dispatcher.new
28
30
  node = Chef::Node.new
@@ -36,4 +38,6 @@ describe Chef::Resource::Directory do
36
38
 
37
39
  it_behaves_like "a directory resource"
38
40
 
41
+ it_behaves_like "a securable resource with reporting"
42
+
39
43
  end
@@ -29,41 +29,75 @@ describe Chef::Resource::File do
29
29
  node = Chef::Node.new
30
30
  run_context = Chef::RunContext.new(node, {}, events)
31
31
  resource = Chef::Resource::File.new(path, run_context)
32
- resource.content(expected_content)
33
32
  resource
34
33
  end
35
34
 
36
35
  let!(:resource) do
36
+ r = create_resource
37
+ r.content(expected_content)
38
+ r
39
+ end
40
+
41
+ let(:resource_without_content) do
37
42
  create_resource
38
43
  end
39
44
 
40
- it_behaves_like "a file resource"
45
+ let(:unmanaged_content) do
46
+ "This is file content that is not managed by chef"
47
+ end
41
48
 
42
- context "when the target file does not exist" do
43
- it "it creates the file when the :touch action is run" do
44
- resource.run_action(:touch)
45
- File.should exist(path)
46
- end
49
+ let(:current_resource) do
50
+ provider = resource.provider_for_action(resource.action)
51
+ provider.load_current_resource
52
+ provider.current_resource
47
53
  end
48
54
 
49
- context "when the target file has the correct content" do
50
- before(:each) do
51
- File.open(path, "w") { |f| f.print expected_content }
52
- end
55
+ let(:default_mode) { ((0100666 - File.umask) & 07777).to_s(8) }
56
+
57
+ it_behaves_like "a file resource"
58
+
59
+ it_behaves_like "a securable resource with reporting"
53
60
 
54
- it "updates the mtime/atime of the file when the :touch action is run" do
55
- expected_mtime = File.stat(path).mtime
56
- expected_atime = File.stat(path).atime
57
- sleep 1
58
- resource.run_action(:touch)
59
- File.stat(path).mtime.should > expected_mtime
60
- File.stat(path).atime.should > expected_atime
61
+ describe "when running action :touch" do
62
+ context "and the target file does not exist" do
63
+ before do
64
+ resource.run_action(:touch)
65
+ end
66
+
67
+ it "it creates the file" do
68
+ File.should exist(path)
69
+ end
70
+
71
+ it "is marked updated by last action" do
72
+ resource.should be_updated_by_last_action
73
+ end
61
74
  end
62
75
 
63
- it "does not change the content when :touch action is run" do
64
- expected_checksum = sha256_checksum(path)
65
- resource.run_action(:touch)
66
- sha256_checksum(path).should == expected_checksum
76
+ context "and the target file exists and has the correct content" do
77
+ before(:each) do
78
+ File.open(path, "w") { |f| f.print expected_content }
79
+
80
+ @expected_checksum = sha256_checksum(path)
81
+
82
+ now = Time.now.to_i
83
+ File.utime(now - 9000, now - 9000, path)
84
+ @expected_mtime = File.stat(path).mtime
85
+
86
+ resource.run_action(:touch)
87
+ end
88
+
89
+ it "updates the mtime of the file" do
90
+ File.stat(path).mtime.should > @expected_mtime
91
+ end
92
+
93
+ it "does not change the content" do
94
+ sha256_checksum(path).should == @expected_checksum
95
+ end
96
+
97
+ it "is marked as updated by last action" do
98
+ resource.should be_updated_by_last_action
99
+ end
67
100
  end
68
101
  end
102
+
69
103
  end
@@ -22,9 +22,11 @@ if windows?
22
22
  require 'chef/win32/file' #probably need this in spec_helper
23
23
  end
24
24
 
25
- describe Chef::Resource::Link do
25
+ describe Chef::Resource::Link, :not_supported_on_win2k3 do
26
26
  let(:file_base) { "file_spec" }
27
27
 
28
+ let(:expect_updated?) {true}
29
+
28
30
  let(:base_dir) do
29
31
  if windows?
30
32
  Chef::ReservedNames::Win32::File.get_long_path_name(Dir.tmpdir.gsub('/', '\\'))
@@ -34,10 +36,10 @@ describe Chef::Resource::Link do
34
36
  end
35
37
 
36
38
  let(:to) do
37
- File.join(base_dir, make_tmpname("to_spec", nil))
39
+ File.join(base_dir, make_tmpname("to_spec"))
38
40
  end
39
41
  let(:target_file) do
40
- File.join(base_dir, make_tmpname("from_spec", nil))
42
+ File.join(base_dir, make_tmpname("from_spec"))
41
43
  end
42
44
 
43
45
  after(:each) do
@@ -268,7 +270,7 @@ describe Chef::Resource::Link do
268
270
  end
269
271
  context 'pointing somewhere else' do
270
272
  before(:each) do
271
- @other_target = File.join(base_dir, make_tmpname('other_spec', nil))
273
+ @other_target = File.join(base_dir, make_tmpname('other_spec'))
272
274
  File.open(@other_target, 'w') { |file| file.write('eek') }
273
275
  symlink(@other_target, target_file)
274
276
  symlink?(target_file).should be_true
@@ -286,7 +288,7 @@ describe Chef::Resource::Link do
286
288
  end
287
289
  context 'pointing nowhere' do
288
290
  before(:each) do
289
- nonexistent = File.join(base_dir, make_tmpname('nonexistent_spec', nil))
291
+ nonexistent = File.join(base_dir, make_tmpname('nonexistent_spec'))
290
292
  symlink(nonexistent, target_file)
291
293
  symlink?(target_file).should be_true
292
294
  readlink(target_file).should == nonexistent
@@ -352,7 +354,7 @@ describe Chef::Resource::Link do
352
354
  context "when the link destination is a symbolic link" do
353
355
  context 'to a file that exists' do
354
356
  before(:each) do
355
- @other_target = File.join(base_dir, make_tmpname("other_spec", nil))
357
+ @other_target = File.join(base_dir, make_tmpname("other_spec"))
356
358
  File.open(@other_target, "w") { |file| file.write("eek") }
357
359
  symlink(@other_target, to)
358
360
  symlink?(to).should be_true
@@ -368,7 +370,7 @@ describe Chef::Resource::Link do
368
370
  end
369
371
  context 'to a file that does not exist' do
370
372
  before(:each) do
371
- @other_target = File.join(base_dir, make_tmpname("other_spec", nil))
373
+ @other_target = File.join(base_dir, make_tmpname("other_spec"))
372
374
  symlink(@other_target, to)
373
375
  symlink?(to).should be_true
374
376
  readlink(to).should == @other_target
@@ -392,7 +394,7 @@ describe Chef::Resource::Link do
392
394
  }.each do |prefix, desc|
393
395
  context desc do
394
396
  let(:to) { "#{prefix}#{File.basename(absolute_to)}" }
395
- let(:absolute_to) { File.join(base_dir, make_tmpname("to_spec", nil)) }
397
+ let(:absolute_to) { File.join(base_dir, make_tmpname("to_spec")) }
396
398
  before(:each) do
397
399
  resource.to(to)
398
400
  end
@@ -511,7 +513,7 @@ describe Chef::Resource::Link do
511
513
  context "when the link destination is a symbolic link" do
512
514
  context 'to a real file' do
513
515
  before(:each) do
514
- @other_target = File.join(base_dir, make_tmpname("other_spec", nil))
516
+ @other_target = File.join(base_dir, make_tmpname("other_spec"))
515
517
  File.open(@other_target, "w") { |file| file.write("eek") }
516
518
  symlink(@other_target, to)
517
519
  symlink?(to).should be_true
@@ -535,7 +537,7 @@ describe Chef::Resource::Link do
535
537
  end
536
538
  context 'to a nonexistent file' do
537
539
  before(:each) do
538
- @other_target = File.join(base_dir, make_tmpname("other_spec", nil))
540
+ @other_target = File.join(base_dir, make_tmpname("other_spec"))
539
541
  symlink(@other_target, to)
540
542
  symlink?(to).should be_true
541
543
  readlink(to).should == @other_target
@@ -0,0 +1,572 @@
1
+ #
2
+ # Author:: Prajakta Purohit (<prajakta@opscode.com>)
3
+ # Author:: Lamont Granquist (<lamont@opscode.com>)
4
+ # Copyright:: Copyright (c) 2011 Opscode, Inc.
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ require "chef/win32/registry"
21
+ require "chef/resource_reporter"
22
+ require "spec_helper"
23
+
24
+ describe Chef::Resource::RegistryKey, :unix_only do
25
+ before(:all) do
26
+ events = Chef::EventDispatch::Dispatcher.new
27
+ node = Chef::Node.new
28
+ ohai = Ohai::System.new
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
+ lambda{@resource.run_action(:create)}.should raise_error(Chef::Exceptions::Win32NotWindows)
39
+ end
40
+ end
41
+ end
42
+
43
+ describe Chef::Resource::RegistryKey, :windows_only do
44
+
45
+ # parent and key must be single keys, not paths
46
+ let(:parent) { 'Opscode' }
47
+ let(:child) { 'Whatever' }
48
+ let(:key_parent) { "SOFTWARE\\" + parent }
49
+ let(:key_child) { "SOFTWARE\\" + parent + "\\" + child }
50
+ # must be under HKLM\SOFTWARE for WOW64 redirection to work
51
+ let(:reg_parent) { "HKLM\\" + key_parent }
52
+ let(:reg_child) { "HKLM\\" + key_child }
53
+ let(:hive_class) { ::Win32::Registry::HKEY_LOCAL_MACHINE }
54
+ let(:resource_name) { "This is the name of my Resource" }
55
+
56
+ def clean_registry
57
+ if windows64?
58
+ # clean 64-bit space on WOW64
59
+ @registry.architecture = :x86_64
60
+ @registry.delete_key(reg_parent, true)
61
+ @registry.architecture = :machine
62
+ end
63
+ # clean 32-bit space on WOW64
64
+ @registry.architecture = :i386
65
+ @registry.delete_key(reg_parent, true)
66
+ @registry.architecture = :machine
67
+ end
68
+
69
+ def reset_registry
70
+ clean_registry
71
+ hive_class.create(key_parent, Win32::Registry::KEY_WRITE | 0x0100)
72
+ hive_class.create(key_parent, Win32::Registry::KEY_WRITE | 0x0200)
73
+ end
74
+
75
+ def create_deletable_keys
76
+ # create them both 32-bit and 64-bit
77
+ [ 0x0100, 0x0200 ].each do |flag|
78
+ hive_class.create(key_parent + '\Opscode', Win32::Registry::KEY_WRITE | flag)
79
+ hive_class.open(key_parent + '\Opscode', Win32::Registry::KEY_ALL_ACCESS | flag) do |reg|
80
+ reg["Color", Win32::Registry::REG_SZ] = "Orange"
81
+ reg.write("Opscode", Win32::Registry::REG_MULTI_SZ, ["Seattle", "Washington"])
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
+ @current_whyrun = Chef::Config[:why_run]
108
+
109
+ reset_registry
110
+ end
111
+
112
+ #Reporting setup
113
+ before do
114
+ @node.name("windowsbox")
115
+ @rest_client = mock("Chef::REST (mock)")
116
+ @rest_client.stub!(:create_url).and_return("reports/nodes/windowsbox/runs/ABC123");
117
+ @rest_client.stub!(:raw_http_request).and_return({"result"=>"ok"});
118
+ @rest_client.stub!(:post_rest).and_return({"uri"=>"https://example.com/reports/nodes/windowsbox/runs/ABC123"});
119
+
120
+ @resource_reporter = Chef::ResourceReporter.new(@rest_client)
121
+ @events.register(@resource_reporter)
122
+ @resource_reporter.node_load_completed(@node, :expanded_run_list, :config)
123
+
124
+ @new_resource.cookbook_name = "monkey"
125
+ @cookbook_version = mock("Cookbook::Version", :version => "1.2.3")
126
+ @new_resource.stub!(:cookbook_version).and_return(@cookbook_version)
127
+ end
128
+
129
+ after (:all) do
130
+ clean_registry
131
+ end
132
+
133
+ context "when action is create" do
134
+ before (:all) do
135
+ reset_registry
136
+ end
137
+ it "creates registry key, value if the key is missing" do
138
+ @new_resource.key(reg_child)
139
+ @new_resource.values([{:name=>"Color", :type=>:string, :data=>"Orange"}])
140
+ @new_resource.run_action(:create)
141
+
142
+ @registry.key_exists?(reg_child).should == true
143
+ @registry.data_exists?(reg_child, {:name=>"Color", :type=>:string, :data=>"Orange"}).should == true
144
+ end
145
+
146
+ it "does not create the key if it already exists with same value, type and data" do
147
+ @new_resource.key(reg_child)
148
+ @new_resource.values([{:name=>"Color", :type=>:string, :data=>"Orange"}])
149
+ @new_resource.run_action(:create)
150
+
151
+ @registry.key_exists?(reg_child).should == true
152
+ @registry.data_exists?(reg_child, {:name=>"Color", :type=>:string, :data=>"Orange"}).should == true
153
+ end
154
+
155
+ it "creates a value if it does not exist" do
156
+ @new_resource.key(reg_child)
157
+ @new_resource.values([{:name=>"Mango", :type=>:string, :data=>"Yellow"}])
158
+ @new_resource.run_action(:create)
159
+
160
+ @registry.data_exists?(reg_child, {:name=>"Mango", :type=>:string, :data=>"Yellow"}).should == true
161
+ end
162
+
163
+ it "modifies the data if the key and value exist and type matches" do
164
+ @new_resource.key(reg_child)
165
+ @new_resource.values([{:name=>"Color", :type=>:string, :data=>"Not just Orange - OpscodeOrange!"}])
166
+ @new_resource.run_action(:create)
167
+
168
+ @registry.data_exists?(reg_child, {:name=>"Color", :type=>:string, :data=>"Not just Orange - OpscodeOrange!"}).should == true
169
+ end
170
+
171
+ it "modifys the type if the key and value exist and the type does not match" do
172
+ @new_resource.key(reg_child)
173
+ @new_resource.values([{:name=>"Color", :type=>:multi_string, :data=>["Not just Orange - OpscodeOrange!"]}])
174
+ @new_resource.run_action(:create)
175
+
176
+ @registry.data_exists?(reg_child, {:name=>"Color", :type=>:multi_string, :data=>["Not just Orange - OpscodeOrange!"]}).should == true
177
+ end
178
+
179
+ it "creates subkey if parent exists" do
180
+ @new_resource.key(reg_child + '\OpscodeTest')
181
+ @new_resource.values([{:name=>"Chef", :type=>:multi_string, :data=>["OpscodeOrange", "Rules"]}])
182
+ @new_resource.recursive(false)
183
+ @new_resource.run_action(:create)
184
+
185
+ @registry.key_exists?(reg_child + '\OpscodeTest').should == true
186
+ @registry.value_exists?(reg_child + '\OpscodeTest', {:name=>"Chef", :type=>:multi_string, :data=>["OpscodeOrange", "Rules"]}).should == true
187
+ end
188
+
189
+ it "gives error if action create and parent does not exist and recursive is set to false" do
190
+ @new_resource.key(reg_child + '\Missing1\Missing2')
191
+ @new_resource.values([{:name=>"OC", :type=>:string, :data=>"MissingData"}])
192
+ @new_resource.recursive(false)
193
+ lambda{@new_resource.run_action(:create)}.should raise_error(Chef::Exceptions::Win32RegNoRecursive)
194
+ end
195
+
196
+ it "creates missing keys if action create and parent does not exist and recursive is set to true" do
197
+ @new_resource.key(reg_child + '\Missing1\Missing2')
198
+ @new_resource.values([{:name=>"OC", :type=>:string, :data=>"MissingData"}])
199
+ @new_resource.recursive(true)
200
+ @new_resource.run_action(:create)
201
+
202
+ @registry.key_exists?(reg_child + '\Missing1\Missing2').should == true
203
+ @registry.value_exists?(reg_child + '\Missing1\Missing2', {:name=>"OC", :type=>:string, :data=>"MissingData"}).should == true
204
+ end
205
+
206
+ it "creates key with multiple value as specified" do
207
+ @new_resource.key(reg_child)
208
+ @new_resource.values([{:name=>"one", :type=>:string, :data=>"1"},{:name=>"two", :type=>:string, :data=>"2"},{:name=>"three", :type=>:string, :data=>"3"}])
209
+ @new_resource.recursive(true)
210
+ @new_resource.run_action(:create)
211
+
212
+ @new_resource.values.each do |value|
213
+ @registry.value_exists?(reg_child, value).should == true
214
+ end
215
+ end
216
+
217
+ context "when running on 64-bit server", :windows64_only do
218
+ before(:all) do
219
+ reset_registry
220
+ end
221
+ after(:all) do
222
+ @new_resource.architecture(:machine)
223
+ @registry.architecture = :machine
224
+ end
225
+ it "creates a key in a 32-bit registry that is not viewable in 64-bit" do
226
+ @new_resource.key(reg_child + '\Atraxi' )
227
+ @new_resource.values([{:name=>"OC", :type=>:string, :data=>"Data"}])
228
+ @new_resource.recursive(true)
229
+ @new_resource.architecture(:i386)
230
+ @new_resource.run_action(:create)
231
+ @registry.architecture = :i386
232
+ @registry.data_exists?(reg_child + '\Atraxi', {:name=>"OC", :type=>:string, :data=>"Data"}).should == true
233
+ @registry.architecture = :x86_64
234
+ @registry.key_exists?(reg_child + '\Atraxi').should == false
235
+ end
236
+ end
237
+
238
+ it "prepares the reporting data for action :create" do
239
+ @new_resource.key(reg_child + '\Ood')
240
+ @new_resource.values([{:name=>"ReportingVal1", :type=>:string, :data=>"report1"},{:name=>"ReportingVal2", :type=>:string, :data=>"report2"}])
241
+ @new_resource.recursive(true)
242
+ @new_resource.run_action(:create)
243
+ @report = @resource_reporter.prepare_run_data
244
+
245
+ @report["action"].should == "end"
246
+ @report["resources"][0]["type"].should == "registry_key"
247
+ @report["resources"][0]["name"].should == resource_name
248
+ @report["resources"][0]["id"].should == reg_child + '\Ood'
249
+ @report["resources"][0]["after"][:values].should == [{:name=>"ReportingVal1", :type=>:string, :data=>"report1"},
250
+ {:name=>"ReportingVal2", :type=>:string, :data=>"report2"}]
251
+ @report["resources"][0]["before"][:values].should == []
252
+ @report["resources"][0]["result"].should == "create"
253
+ @report["status"].should == "success"
254
+ @report["total_res_count"].should == "1"
255
+ end
256
+
257
+ context "while running in whyrun mode" do
258
+ before (:all) do
259
+ Chef::Config[:why_run] = true
260
+ end
261
+ after (:all) do
262
+ Chef::Config[:why_run] = @current_whyrun
263
+ end
264
+
265
+ it "does not throw an exception if the keys do not exist but recursive is set to false" do
266
+ @new_resource.key(reg_child + '\Slitheen\Raxicoricofallapatorius')
267
+ @new_resource.values([{:name=>"BriskWalk",:type=>:string,:data=>"is good for health"}])
268
+ @new_resource.recursive(false)
269
+ lambda{@new_resource.run_action(:create)}.should_not raise_error
270
+ @registry.key_exists?(reg_child + '\Slitheen').should == false
271
+ @registry.key_exists?(reg_child + '\Slitheen\Raxicoricofallapatorius').should == false
272
+ end
273
+ it "does not create key if the action is create" do
274
+ @new_resource.key(reg_child + '\Slitheen')
275
+ @new_resource.values([{:name=>"BriskWalk",:type=>:string,:data=>"is good for health"}])
276
+ @new_resource.recursive(false)
277
+ @new_resource.run_action(:create)
278
+ @registry.key_exists?(reg_child + '\Slitheen').should == false
279
+ end
280
+ end
281
+ end
282
+
283
+ context "when action is create_if_missing" do
284
+ before (:all) do
285
+ reset_registry
286
+ end
287
+
288
+ it "creates registry key, value if the key is missing" do
289
+ @new_resource.key(reg_child)
290
+ @new_resource.values([{:name=>"Color", :type=>:string, :data=>"Orange"}])
291
+ @new_resource.run_action(:create_if_missing)
292
+
293
+ @registry.key_exists?(reg_parent).should == true
294
+ @registry.key_exists?(reg_child).should == true
295
+ @registry.data_exists?(reg_child, {:name=>"Color", :type=>:string, :data=>"Orange"}).should == true
296
+ end
297
+
298
+ it "does not create the key if it already exists with same value, type and data" do
299
+ @new_resource.key(reg_child)
300
+ @new_resource.values([{:name=>"Color", :type=>:string, :data=>"Orange"}])
301
+ @new_resource.run_action(:create_if_missing)
302
+
303
+ @registry.key_exists?(reg_child).should == true
304
+ @registry.data_exists?(reg_child, {:name=>"Color", :type=>:string, :data=>"Orange"}).should == true
305
+ end
306
+
307
+ it "creates a value if it does not exist" do
308
+ @new_resource.key(reg_child)
309
+ @new_resource.values([{:name=>"Mango", :type=>:string, :data=>"Yellow"}])
310
+ @new_resource.run_action(:create_if_missing)
311
+
312
+ @registry.data_exists?(reg_child, {:name=>"Mango", :type=>:string, :data=>"Yellow"}).should == true
313
+ end
314
+
315
+ it "creates subkey if parent exists" do
316
+ @new_resource.key(reg_child + '\Pyrovile')
317
+ @new_resource.values([{:name=>"Chef", :type=>:multi_string, :data=>["OpscodeOrange", "Rules"]}])
318
+ @new_resource.recursive(false)
319
+ @new_resource.run_action(:create_if_missing)
320
+
321
+ @registry.key_exists?(reg_child + '\Pyrovile').should == true
322
+ @registry.value_exists?(reg_child + '\Pyrovile', {:name=>"Chef", :type=>:multi_string, :data=>["OpscodeOrange", "Rules"]}).should == true
323
+ end
324
+
325
+ it "gives error if action create and parent does not exist and recursive is set to false" do
326
+ @new_resource.key(reg_child + '\Sontaran\Sontar')
327
+ @new_resource.values([{:name=>"OC", :type=>:string, :data=>"MissingData"}])
328
+ @new_resource.recursive(false)
329
+ lambda{@new_resource.run_action(:create_if_missing)}.should raise_error(Chef::Exceptions::Win32RegNoRecursive)
330
+ end
331
+
332
+ it "creates missing keys if action create and parent does not exist and recursive is set to true" do
333
+ @new_resource.key(reg_child + '\Sontaran\Sontar')
334
+ @new_resource.values([{:name=>"OC", :type=>:string, :data=>"MissingData"}])
335
+ @new_resource.recursive(true)
336
+ @new_resource.run_action(:create_if_missing)
337
+
338
+ @registry.key_exists?(reg_child + '\Sontaran\Sontar').should == true
339
+ @registry.value_exists?(reg_child + '\Sontaran\Sontar', {:name=>"OC", :type=>:string, :data=>"MissingData"}).should == true
340
+ end
341
+
342
+ it "creates key with multiple value as specified" do
343
+ @new_resource.key(reg_child + '\Adipose')
344
+ @new_resource.values([{:name=>"one", :type=>:string, :data=>"1"},{:name=>"two", :type=>:string, :data=>"2"},{:name=>"three", :type=>:string, :data=>"3"}])
345
+ @new_resource.recursive(true)
346
+ @new_resource.run_action(:create_if_missing)
347
+
348
+ @new_resource.values.each do |value|
349
+ @registry.value_exists?(reg_child + '\Adipose', value).should == true
350
+ end
351
+ end
352
+
353
+ it "prepares the reporting data for :create_if_missing" do
354
+ @new_resource.key(reg_child + '\Judoon')
355
+ @new_resource.values([{:name=>"ReportingVal3", :type=>:string, :data=>"report3"}])
356
+ @new_resource.recursive(true)
357
+ @new_resource.run_action(:create_if_missing)
358
+ @report = @resource_reporter.prepare_run_data
359
+
360
+ @report["action"].should == "end"
361
+ @report["resources"][0]["type"].should == "registry_key"
362
+ @report["resources"][0]["name"].should == resource_name
363
+ @report["resources"][0]["id"].should == reg_child + '\Judoon'
364
+ @report["resources"][0]["after"][:values].should == [{:name=>"ReportingVal3", :type=>:string, :data=>"report3"}]
365
+ @report["resources"][0]["before"][:values].should == []
366
+ @report["resources"][0]["result"].should == "create_if_missing"
367
+ @report["status"].should == "success"
368
+ @report["total_res_count"].should == "1"
369
+ end
370
+
371
+ context "while running in whyrun mode" do
372
+ before (:all) do
373
+ Chef::Config[:why_run] = true
374
+ end
375
+ after (:all) do
376
+ Chef::Config[:why_run] = @current_whyrun
377
+ end
378
+
379
+ it "does not throw an exception if the keys do not exist but recursive is set to false" do
380
+ @new_resource.key(reg_child + '\Zygons\Zygor')
381
+ @new_resource.values([{:name=>"BriskWalk",:type=>:string,:data=>"is good for health"}])
382
+ @new_resource.recursive(false)
383
+ lambda{@new_resource.run_action(:create_if_missing)}.should_not raise_error
384
+ @registry.key_exists?(reg_child + '\Zygons').should == false
385
+ @registry.key_exists?(reg_child + '\Zygons\Zygor').should == false
386
+ end
387
+ it "does nothing if the action is create_if_missing" do
388
+ @new_resource.key(reg_child + '\Zygons')
389
+ @new_resource.values([{:name=>"BriskWalk",:type=>:string,:data=>"is good for health"}])
390
+ @new_resource.recursive(false)
391
+ @new_resource.run_action(:create_if_missing)
392
+ @registry.key_exists?(reg_child + '\Zygons').should == false
393
+ end
394
+ end
395
+ end
396
+
397
+ context "when the action is delete" do
398
+ before(:all) do
399
+ reset_registry
400
+ create_deletable_keys
401
+ end
402
+
403
+ it "takes no action if the specified key path does not exist in the system" do
404
+ @registry.key_exists?(reg_parent + '\Osirian').should == false
405
+
406
+ @new_resource.key(reg_parent+ '\Osirian')
407
+ @new_resource.recursive(false)
408
+ @new_resource.run_action(:delete)
409
+
410
+ @registry.key_exists?(reg_parent + '\Osirian').should == false
411
+ end
412
+
413
+ it "takes no action if the key exists but the value does not" do
414
+ @registry.data_exists?(reg_parent + '\Opscode', {:name=>"Color", :type=>:string, :data=>"Orange"}).should == true
415
+
416
+ @new_resource.key(reg_parent + '\Opscode')
417
+ @new_resource.values([{:name=>"LooksLike", :type=>:multi_string, :data=>["SeattleGrey", "OCOrange"]}])
418
+ @new_resource.recursive(false)
419
+ @new_resource.run_action(:delete)
420
+
421
+ @registry.data_exists?(reg_parent + '\Opscode', {:name=>"Color", :type=>:string, :data=>"Orange"}).should == true
422
+ end
423
+
424
+ it "deletes only specified values under a key path" do
425
+ @new_resource.key(reg_parent + '\Opscode')
426
+ @new_resource.values([{:name=>"Opscode", :type=>:multi_string, :data=>["Seattle", "Washington"]}, {:name=>"AKA", :type=>:string, :data=>"OC"}])
427
+ @new_resource.recursive(false)
428
+ @new_resource.run_action(:delete)
429
+
430
+ @registry.data_exists?(reg_parent + '\Opscode', {:name=>"Color", :type=>:string, :data=>"Orange"}).should == true
431
+ @registry.value_exists?(reg_parent + '\Opscode', {:name=>"AKA", :type=>:string, :data=>"OC"}).should == false
432
+ @registry.value_exists?(reg_parent + '\Opscode', {:name=>"Opscode", :type=>:multi_string, :data=>["Seattle", "Washington"]}).should == false
433
+ end
434
+
435
+ it "it deletes the values with the same name irrespective of it type and data" do
436
+ @new_resource.key(reg_parent + '\Opscode')
437
+ @new_resource.values([{:name=>"Color", :type=>:multi_string, :data=>["Black", "Orange"]}])
438
+ @new_resource.recursive(false)
439
+ @new_resource.run_action(:delete)
440
+
441
+ @registry.value_exists?(reg_parent + '\Opscode', {:name=>"Color", :type=>:string, :data=>"Orange"}).should == false
442
+ end
443
+
444
+ it "prepares the reporting data for action :delete" do
445
+ @new_resource.key(reg_parent + '\ReportKey')
446
+ @new_resource.values([{:name=>"ReportVal4", :type=>:string, :data=>"report4"},{:name=>"ReportVal5", :type=>:string, :data=>"report5"}])
447
+ @new_resource.recursive(true)
448
+ @new_resource.run_action(:delete)
449
+
450
+ @report = @resource_reporter.prepare_run_data
451
+
452
+ @registry.value_exists?(reg_parent + '\ReportKey', [{:name=>"ReportVal4", :type=>:string, :data=>"report4"},{:name=>"ReportVal5", :type=>:string, :data=>"report5"}]).should == false
453
+
454
+ @report["action"].should == "end"
455
+ @report["resources"].count.should == 1
456
+ @report["resources"][0]["type"].should == "registry_key"
457
+ @report["resources"][0]["name"].should == resource_name
458
+ @report["resources"][0]["id"].should == reg_parent + '\ReportKey'
459
+ @report["resources"][0]["before"][:values].should == [{:name=>"ReportVal4", :type=>:string, :data=>"report4"},
460
+ {:name=>"ReportVal5", :type=>:string, :data=>"report5"}]
461
+ #Not testing for after values to match since after -> new_resource values.
462
+ @report["resources"][0]["result"].should == "delete"
463
+ @report["status"].should == "success"
464
+ @report["total_res_count"].should == "1"
465
+ end
466
+
467
+ context "while running in whyrun mode" do
468
+ before (:all) do
469
+ Chef::Config[:why_run] = true
470
+ end
471
+ after (:all) do
472
+ Chef::Config[:why_run] = @current_whyrun
473
+ end
474
+ it "does nothing if the action is delete" do
475
+ @new_resource.key(reg_parent + '\OpscodeWhyRun')
476
+ @new_resource.values([{:name=>"BriskWalk",:type=>:string,:data=>"is good for health"}])
477
+ @new_resource.recursive(false)
478
+ @new_resource.run_action(:delete)
479
+
480
+ @registry.key_exists?(reg_parent + '\OpscodeWhyRun').should == true
481
+ end
482
+ end
483
+ end
484
+
485
+ context "when the action is delete_key" do
486
+ before (:all) do
487
+ reset_registry
488
+ create_deletable_keys
489
+ end
490
+
491
+ it "takes no action if the specified key path does not exist in the system" do
492
+ @registry.key_exists?(reg_parent + '\Osirian').should == false
493
+
494
+ @new_resource.key(reg_parent + '\Osirian')
495
+ @new_resource.recursive(false)
496
+ @new_resource.run_action(:delete_key)
497
+
498
+ @registry.key_exists?(reg_parent + '\Osirian').should == false
499
+ end
500
+
501
+ it "deletes key if it has no subkeys and recursive == false" do
502
+ @new_resource.key(reg_parent + '\OpscodeTest')
503
+ @new_resource.recursive(false)
504
+ @new_resource.run_action(:delete_key)
505
+
506
+ @registry.key_exists?(reg_parent + '\OpscodeTest').should == false
507
+ end
508
+
509
+ it "raises an exception if the the key has subkeys and recursive == false" do
510
+ @new_resource.key(reg_parent)
511
+ @new_resource.recursive(false)
512
+ lambda{@new_resource.run_action(:delete_key)}.should raise_error(Chef::Exceptions::Win32RegNoRecursive)
513
+ end
514
+
515
+ it "ignores the values under a key" do
516
+ @new_resource.key(reg_parent + '\OpscodeIgnoredValues')
517
+ #@new_resource.values([{:name=>"DontExist", :type=>:string, :data=>"These will be ignored anyways"}])
518
+ @new_resource.recursive(true)
519
+ @new_resource.run_action(:delete_key)
520
+ end
521
+
522
+ it "deletes the key if it has subkeys and recursive == true" do
523
+ @new_resource.key(reg_parent + '\Opscode')
524
+ @new_resource.recursive(true)
525
+ @new_resource.run_action(:delete_key)
526
+
527
+ @registry.key_exists?(reg_parent + '\Opscode').should == false
528
+ end
529
+
530
+ it "prepares the reporting data for action :delete_key" do
531
+ @new_resource.key(reg_parent + '\ReportKey')
532
+ @new_resource.recursive(true)
533
+ @new_resource.run_action(:delete_key)
534
+
535
+ @report = @resource_reporter.prepare_run_data
536
+ @report["action"].should == "end"
537
+ @report["resources"][0]["type"].should == "registry_key"
538
+ @report["resources"][0]["name"].should == resource_name
539
+ @report["resources"][0]["id"].should == reg_parent + '\ReportKey'
540
+ #Not testing for before or after values to match since
541
+ #after -> new_resource.values and
542
+ #before -> current_resource.values
543
+ @report["resources"][0]["result"].should == "delete_key"
544
+ @report["status"].should == "success"
545
+ @report["total_res_count"].should == "1"
546
+ end
547
+ context "while running in whyrun mode" do
548
+ before (:all) do
549
+ Chef::Config[:why_run] = true
550
+ end
551
+ after (:all) do
552
+ Chef::Config[:why_run] = @current_whyrun
553
+ end
554
+
555
+ it "does not throw an exception if the key has subkeys but recursive is set to false" do
556
+ @new_resource.key(reg_parent + '\OpscodeWhyRun')
557
+ @new_resource.values([{:name=>"BriskWalk",:type=>:string,:data=>"is good for health"}])
558
+ @new_resource.recursive(false)
559
+ @new_resource.run_action(:delete_key)
560
+ @new_resource.should_not raise_error(ArgumentError)
561
+ end
562
+ it "does nothing if the action is delete_key" do
563
+ @new_resource.key(reg_parent + '\OpscodeWhyRun')
564
+ @new_resource.values([{:name=>"BriskWalk",:type=>:string,:data=>"is good for health"}])
565
+ @new_resource.recursive(false)
566
+ @new_resource.run_action(:delete_key)
567
+
568
+ @registry.key_exists?(reg_parent + '\OpscodeWhyRun').should == true
569
+ end
570
+ end
571
+ end
572
+ end