chef 12.5.0.alpha.1 → 12.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (275) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +21 -25
  3. data/Gemfile +46 -0
  4. data/README.md +4 -4
  5. data/Rakefile +5 -110
  6. data/distro/common/html/knife_cookbook_site.html +18 -18
  7. data/distro/common/man/man1/knife-cookbook-site.1 +11 -11
  8. data/lib/chef/application.rb +1 -1
  9. data/lib/chef/application/apply.rb +19 -1
  10. data/lib/chef/application/client.rb +11 -5
  11. data/lib/chef/application/knife.rb +2 -2
  12. data/lib/chef/application/windows_service_manager.rb +9 -7
  13. data/lib/chef/chef_class.rb +39 -0
  14. data/lib/chef/chef_fs/data_handler/client_data_handler.rb +3 -1
  15. data/lib/chef/chef_fs/file_system/acl_dir.rb +3 -4
  16. data/lib/chef/chef_fs/file_system/acls_dir.rb +5 -1
  17. data/lib/chef/chef_fs/file_system/base_fs_dir.rb +0 -5
  18. data/lib/chef/chef_fs/file_system/base_fs_object.rb +5 -2
  19. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb +2 -9
  20. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_entry.rb +2 -9
  21. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb +10 -17
  22. data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +1 -12
  23. data/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb +15 -11
  24. data/lib/chef/chef_fs/file_system/chef_server_root_dir.rb +8 -2
  25. data/lib/chef/chef_fs/file_system/cookbook_dir.rb +3 -4
  26. data/lib/chef/chef_fs/file_system/cookbooks_acl_dir.rb +1 -1
  27. data/lib/chef/chef_fs/file_system/cookbooks_dir.rb +3 -11
  28. data/lib/chef/chef_fs/file_system/data_bags_dir.rb +3 -5
  29. data/lib/chef/chef_fs/file_system/environments_dir.rb +1 -1
  30. data/lib/chef/chef_fs/file_system/file_system_entry.rb +7 -4
  31. data/lib/chef/chef_fs/file_system/memory_dir.rb +2 -3
  32. data/lib/chef/chef_fs/file_system/multiplexed_dir.rb +15 -0
  33. data/lib/chef/chef_fs/file_system/nodes_dir.rb +1 -1
  34. data/lib/chef/chef_fs/file_system/organization_members_entry.rb +2 -2
  35. data/lib/chef/chef_fs/file_system/rest_list_dir.rb +4 -9
  36. data/lib/chef/client.rb +2 -3
  37. data/lib/chef/config.rb +34 -2
  38. data/lib/chef/cookbook/metadata.rb +25 -3
  39. data/lib/chef/cookbook/synchronizer.rb +1 -1
  40. data/lib/chef/cookbook_site_streaming_uploader.rb +1 -1
  41. data/lib/chef/cookbook_version.rb +3 -3
  42. data/lib/chef/deprecation/mixin/template.rb +1 -2
  43. data/lib/chef/deprecation/provider/cookbook_file.rb +1 -1
  44. data/lib/chef/deprecation/provider/file.rb +1 -1
  45. data/lib/chef/deprecation/provider/remote_directory.rb +52 -0
  46. data/lib/chef/deprecation/provider/remote_file.rb +1 -2
  47. data/lib/chef/deprecation/provider/template.rb +1 -1
  48. data/lib/chef/deprecation/warnings.rb +3 -4
  49. data/lib/chef/dsl/reboot_pending.rb +3 -2
  50. data/lib/chef/dsl/recipe.rb +6 -5
  51. data/lib/chef/dsl/resources.rb +2 -2
  52. data/lib/chef/event_dispatch/base.rb +12 -7
  53. data/lib/chef/event_dispatch/dispatcher.rb +21 -6
  54. data/lib/chef/exceptions.rb +22 -0
  55. data/lib/chef/file_content_management/tempfile.rb +1 -1
  56. data/lib/chef/formatters/base.rb +3 -0
  57. data/lib/chef/formatters/doc.rb +53 -5
  58. data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +36 -0
  59. data/lib/chef/formatters/minimal.rb +2 -2
  60. data/lib/chef/knife.rb +35 -55
  61. data/lib/chef/knife/bootstrap.rb +41 -0
  62. data/lib/chef/knife/bootstrap/chef_vault_handler.rb +1 -0
  63. data/lib/chef/knife/bootstrap/client_builder.rb +16 -0
  64. data/lib/chef/knife/bootstrap/templates/README.md +3 -4
  65. data/lib/chef/knife/cookbook_create.rb +1 -1
  66. data/lib/chef/knife/cookbook_site_download.rb +1 -1
  67. data/lib/chef/knife/cookbook_site_install.rb +1 -1
  68. data/lib/chef/knife/cookbook_site_share.rb +6 -6
  69. data/lib/chef/knife/cookbook_site_unshare.rb +2 -2
  70. data/lib/chef/knife/core/bootstrap_context.rb +12 -4
  71. data/lib/chef/knife/core/custom_manifest_loader.rb +69 -0
  72. data/lib/chef/knife/core/gem_glob_loader.rb +138 -0
  73. data/lib/chef/knife/core/hashed_command_loader.rb +80 -0
  74. data/lib/chef/knife/core/node_presenter.rb +24 -1
  75. data/lib/chef/knife/core/object_loader.rb +1 -0
  76. data/lib/chef/knife/core/subcommand_loader.rb +131 -146
  77. data/lib/chef/knife/node_run_list_remove.rb +12 -1
  78. data/lib/chef/knife/null.rb +10 -0
  79. data/lib/chef/knife/rehash.rb +62 -0
  80. data/lib/chef/knife/search.rb +3 -3
  81. data/lib/chef/knife/ssh.rb +52 -30
  82. data/lib/chef/local_mode.rb +5 -0
  83. data/lib/chef/log.rb +5 -1
  84. data/lib/chef/mixin/deprecation.rb +8 -8
  85. data/lib/chef/mixin/params_validate.rb +2 -2
  86. data/lib/chef/mixin/template.rb +48 -0
  87. data/lib/chef/mixin/which.rb +1 -1
  88. data/lib/chef/mixin/wide_string.rb +72 -0
  89. data/lib/chef/mixin/windows_architecture_helper.rb +15 -39
  90. data/lib/chef/mixin/windows_env_helper.rb +4 -1
  91. data/lib/chef/monkey_patches/webrick-utils.rb +51 -0
  92. data/lib/chef/monkey_patches/win32/registry.rb +72 -0
  93. data/lib/chef/node.rb +97 -3
  94. data/lib/chef/node_map.rb +2 -2
  95. data/lib/chef/platform/provider_mapping.rb +5 -6
  96. data/lib/chef/platform/query_helpers.rb +46 -4
  97. data/lib/chef/platform/service_helpers.rb +30 -32
  98. data/lib/chef/policy_builder.rb +1 -8
  99. data/lib/chef/policy_builder/dynamic.rb +186 -0
  100. data/lib/chef/policy_builder/expand_node_object.rb +30 -15
  101. data/lib/chef/policy_builder/policyfile.rb +155 -18
  102. data/lib/chef/property.rb +38 -9
  103. data/lib/chef/provider.rb +104 -12
  104. data/lib/chef/provider/batch.rb +8 -0
  105. data/lib/chef/provider/deploy.rb +2 -2
  106. data/lib/chef/provider/directory.rb +14 -2
  107. data/lib/chef/provider/dsc_resource.rb +5 -9
  108. data/lib/chef/provider/group/pw.rb +1 -1
  109. data/lib/chef/provider/ifconfig.rb +2 -2
  110. data/lib/chef/provider/mount.rb +7 -3
  111. data/lib/chef/provider/package/dpkg.rb +5 -11
  112. data/lib/chef/provider/package/rpm.rb +2 -2
  113. data/lib/chef/provider/package/rubygems.rb +1 -1
  114. data/lib/chef/provider/package/windows/msi.rb +2 -2
  115. data/lib/chef/provider/package/yum.rb +17 -5
  116. data/lib/chef/provider/powershell_script.rb +27 -4
  117. data/lib/chef/provider/remote_directory.rb +190 -102
  118. data/lib/chef/provider/service.rb +12 -2
  119. data/lib/chef/provider/service/aix.rb +1 -1
  120. data/lib/chef/provider/service/debian.rb +3 -5
  121. data/lib/chef/provider/service/freebsd.rb +1 -1
  122. data/lib/chef/provider/service/gentoo.rb +3 -3
  123. data/lib/chef/provider/service/init.rb +3 -3
  124. data/lib/chef/provider/service/insserv.rb +2 -4
  125. data/lib/chef/provider/service/invokercd.rb +2 -4
  126. data/lib/chef/provider/service/openbsd.rb +2 -1
  127. data/lib/chef/provider/service/redhat.rb +52 -16
  128. data/lib/chef/provider/service/simple.rb +2 -2
  129. data/lib/chef/provider/service/systemd.rb +3 -5
  130. data/lib/chef/provider/service/upstart.rb +4 -6
  131. data/lib/chef/provider/subversion.rb +13 -7
  132. data/lib/chef/provider/template/content.rb +16 -6
  133. data/lib/chef/provider/user/solaris.rb +32 -4
  134. data/lib/chef/provider/windows_script.rb +3 -5
  135. data/lib/chef/provider_resolver.rb +2 -2
  136. data/lib/chef/resource.rb +85 -27
  137. data/lib/chef/resource/action_class.rb +83 -0
  138. data/lib/chef/resource/chef_gem.rb +3 -3
  139. data/lib/chef/resource/deploy.rb +8 -2
  140. data/lib/chef/resource/dsc_script.rb +2 -0
  141. data/lib/chef/resource/file/verification.rb +1 -1
  142. data/lib/chef/resource/registry_key.rb +1 -1
  143. data/lib/chef/resource/service.rb +10 -2
  144. data/lib/chef/resource/subversion.rb +5 -0
  145. data/lib/chef/resource/windows_script.rb +6 -2
  146. data/lib/chef/resource/yum_package.rb +10 -1
  147. data/lib/chef/resource_resolver.rb +3 -3
  148. data/lib/chef/run_context.rb +6 -8
  149. data/lib/chef/run_list/versioned_recipe_list.rb +15 -0
  150. data/lib/chef/run_lock.rb +30 -21
  151. data/lib/chef/util/powershell/ps_credential.rb +4 -0
  152. data/lib/chef/util/windows.rb +0 -32
  153. data/lib/chef/util/windows/net_group.rb +85 -106
  154. data/lib/chef/util/windows/net_use.rb +35 -71
  155. data/lib/chef/util/windows/net_user.rb +0 -1
  156. data/lib/chef/util/windows/volume.rb +19 -19
  157. data/lib/chef/version.rb +3 -3
  158. data/lib/chef/win32/api.rb +1 -0
  159. data/lib/chef/win32/api/file.rb +20 -0
  160. data/lib/chef/win32/api/net.rb +163 -43
  161. data/lib/chef/win32/api/registry.rb +51 -0
  162. data/lib/chef/win32/api/system.rb +23 -0
  163. data/lib/chef/win32/api/unicode.rb +0 -43
  164. data/lib/chef/win32/crypto.rb +2 -1
  165. data/lib/chef/win32/file.rb +28 -3
  166. data/lib/chef/win32/mutex.rb +1 -2
  167. data/lib/chef/win32/net.rb +162 -8
  168. data/lib/chef/win32/process.rb +13 -0
  169. data/lib/chef/win32/registry.rb +25 -28
  170. data/lib/chef/win32/security.rb +1 -1
  171. data/lib/chef/win32/security/token.rb +1 -1
  172. data/lib/chef/win32/system.rb +62 -0
  173. data/lib/chef/win32/unicode.rb +7 -2
  174. data/lib/chef/win32/version.rb +0 -4
  175. data/spec/data/cookbooks/openldap/templates/default/helpers.erb +14 -0
  176. data/spec/data/cookbooks/openldap/templates/default/nested_openldap_partials.erb +1 -0
  177. data/spec/data/cookbooks/openldap/templates/default/nested_partial.erb +1 -0
  178. data/spec/data/dsc_lcm.pfx +0 -0
  179. data/spec/functional/dsl/reboot_pending_spec.rb +33 -43
  180. data/spec/functional/knife/cookbook_delete_spec.rb +17 -7
  181. data/spec/functional/knife/ssh_spec.rb +16 -0
  182. data/spec/functional/resource/deploy_revision_spec.rb +1 -1
  183. data/spec/functional/resource/dsc_resource_spec.rb +2 -0
  184. data/spec/functional/resource/dsc_script_spec.rb +91 -2
  185. data/spec/functional/resource/group_spec.rb +67 -44
  186. data/spec/functional/resource/powershell_script_spec.rb +104 -15
  187. data/spec/functional/resource/windows_service_spec.rb +1 -1
  188. data/spec/functional/run_lock_spec.rb +368 -189
  189. data/spec/functional/win32/{registry_helper_spec.rb → registry_spec.rb} +4 -23
  190. data/spec/integration/client/client_spec.rb +51 -0
  191. data/spec/integration/knife/download_spec.rb +4 -0
  192. data/spec/integration/knife/list_spec.rb +8 -0
  193. data/spec/integration/knife/upload_spec.rb +1 -1
  194. data/spec/integration/recipes/recipe_dsl_spec.rb +1 -1
  195. data/spec/integration/recipes/remote_directory.rb +74 -0
  196. data/spec/integration/recipes/resource_action_spec.rb +42 -22
  197. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +423 -0
  198. data/spec/integration/recipes/resource_load_spec.rb +206 -0
  199. data/spec/spec_helper.rb +8 -0
  200. data/spec/support/platform_helpers.rb +13 -0
  201. data/{lib/chef/mixin/wstring.rb → spec/support/shared/context/win32.rb} +15 -12
  202. data/spec/support/shared/functional/windows_script.rb +63 -26
  203. data/spec/support/shared/unit/mock_shellout.rb +46 -0
  204. data/spec/support/shared/unit/provider/file.rb +10 -4
  205. data/spec/unit/application/client_spec.rb +16 -3
  206. data/spec/unit/application/knife_spec.rb +2 -2
  207. data/spec/unit/chef_class_spec.rb +0 -4
  208. data/spec/unit/client_spec.rb +6 -1
  209. data/spec/unit/config_spec.rb +31 -0
  210. data/spec/unit/cookbook/metadata_spec.rb +23 -3
  211. data/spec/unit/cookbook/syntax_check_spec.rb +3 -0
  212. data/spec/unit/deprecation_spec.rb +3 -6
  213. data/spec/unit/dsl/reboot_pending_spec.rb +12 -6
  214. data/spec/unit/event_dispatch/dispatcher_spec.rb +65 -3
  215. data/spec/unit/event_dispatch/dsl_spec.rb +0 -4
  216. data/spec/unit/formatters/doc_spec.rb +32 -0
  217. data/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +26 -0
  218. data/spec/unit/knife/bootstrap/client_builder_spec.rb +27 -0
  219. data/spec/unit/knife/bootstrap_spec.rb +55 -3
  220. data/spec/unit/knife/cookbook_site_share_spec.rb +3 -3
  221. data/spec/unit/knife/core/bootstrap_context_spec.rb +21 -4
  222. data/spec/unit/knife/core/custom_manifest_loader_spec.rb +41 -0
  223. data/spec/unit/knife/core/gem_glob_loader_spec.rb +210 -0
  224. data/spec/unit/knife/core/hashed_command_loader_spec.rb +93 -0
  225. data/spec/unit/knife/core/subcommand_loader_spec.rb +16 -192
  226. data/spec/unit/knife/node_run_list_remove_spec.rb +17 -0
  227. data/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +10 -10
  228. data/spec/unit/mixin/template_spec.rb +5 -1
  229. data/spec/unit/mixin/windows_architecture_helper_spec.rb +13 -8
  230. data/spec/unit/node_spec.rb +213 -0
  231. data/spec/unit/platform/query_helpers_spec.rb +146 -3
  232. data/spec/unit/policy_builder/dynamic_spec.rb +275 -0
  233. data/spec/unit/policy_builder/expand_node_object_spec.rb +37 -38
  234. data/spec/unit/policy_builder/policyfile_spec.rb +260 -46
  235. data/spec/unit/property/validation_spec.rb +5 -0
  236. data/spec/unit/property_spec.rb +152 -26
  237. data/spec/unit/provider/deploy_spec.rb +5 -5
  238. data/spec/unit/provider/directory_spec.rb +35 -0
  239. data/spec/unit/provider/dsc_resource_spec.rb +3 -10
  240. data/spec/unit/provider/ifconfig_spec.rb +22 -2
  241. data/spec/unit/provider/mount/aix_spec.rb +2 -1
  242. data/spec/unit/provider/mount/mount_spec.rb +6 -0
  243. data/spec/unit/provider/mount/windows_spec.rb +14 -0
  244. data/spec/unit/provider/mount_spec.rb +12 -1
  245. data/spec/unit/provider/package/dpkg_spec.rb +8 -1
  246. data/spec/unit/provider/package/rpm_spec.rb +18 -1
  247. data/spec/unit/provider/package/rubygems_spec.rb +18 -0
  248. data/spec/unit/provider/package/yum_spec.rb +97 -24
  249. data/spec/unit/provider/powershell_script_spec.rb +52 -26
  250. data/spec/unit/provider/remote_directory_spec.rb +1 -2
  251. data/spec/unit/provider/service/aix_service_spec.rb +3 -3
  252. data/spec/unit/provider/service/gentoo_service_spec.rb +4 -4
  253. data/spec/unit/provider/service/openbsd_service_spec.rb +10 -8
  254. data/spec/unit/provider/service/redhat_spec.rb +88 -8
  255. data/spec/unit/provider/service/upstart_service_spec.rb +11 -7
  256. data/spec/unit/provider/service/windows_spec.rb +211 -200
  257. data/spec/unit/provider/subversion_spec.rb +50 -31
  258. data/spec/unit/provider/template/content_spec.rb +93 -2
  259. data/spec/unit/provider/user/solaris_spec.rb +66 -9
  260. data/spec/unit/provider_resolver_spec.rb +707 -650
  261. data/spec/unit/resource/deploy_spec.rb +7 -1
  262. data/spec/unit/resource/dsc_script_spec.rb +4 -0
  263. data/spec/unit/resource/file/verification_spec.rb +1 -1
  264. data/spec/unit/resource/powershell_script_spec.rb +17 -13
  265. data/spec/unit/resource/service_spec.rb +4 -4
  266. data/spec/unit/resource/subversion_spec.rb +4 -0
  267. data/spec/unit/resource/yum_package_spec.rb +10 -1
  268. data/spec/unit/run_list/versioned_recipe_list_spec.rb +5 -0
  269. data/spec/unit/win32/registry_spec.rb +394 -0
  270. data/tasks/external_tests.rb +47 -23
  271. data/tasks/maintainers.rb +155 -14
  272. metadata +51 -26
  273. data/lib/chef/knife/bootstrap/templates/archlinux-gems.erb +0 -76
  274. data/lib/chef/knife/bootstrap/templates/chef-aix.erb +0 -72
  275. data/spec/unit/registry_helper_spec.rb +0 -390
@@ -148,10 +148,16 @@ describe Chef::Resource::Deploy do
148
148
  expect(@resource.current_path).to eql("/my/deploy/dir/current")
149
149
  end
150
150
 
151
+ it "allows depth to be set via integer" do
152
+ expect(@resource.depth).to be_nil
153
+ @resource.depth 1
154
+ expect(@resource.depth).to eql(1)
155
+ end
156
+
151
157
  it "gives #depth as 5 if shallow clone is true, nil otherwise" do
152
158
  expect(@resource.depth).to be_nil
153
159
  @resource.shallow_clone true
154
- expect(@resource.depth).to eql("5")
160
+ expect(@resource.depth).to eql(5)
155
161
  end
156
162
 
157
163
  it "aliases repo as repository" do
@@ -70,6 +70,10 @@ describe Chef::Resource::DscScript do
70
70
  expect(dsc_test_resource.configuration_data_script).to eq(configuration_data_script)
71
71
  end
72
72
 
73
+ it "has the ps_credential helper method" do
74
+ expect(dsc_test_resource).to respond_to(:ps_credential)
75
+ end
76
+
73
77
  context "when calling imports" do
74
78
  let(:module_name) { 'FooModule' }
75
79
  let(:module_name_b) { 'BarModule' }
@@ -88,7 +88,7 @@ describe Chef::Resource::File::Verification do
88
88
  end
89
89
 
90
90
  it "warns about deprecation when \%{file} is used" do
91
- expect(Chef::Log).to receive(:deprecation).with(/%{file} is deprecated/)
91
+ expect(Chef::Log).to receive(:deprecation).with(/%{file} is deprecated/, /verification_spec\.rb/)
92
92
  test_command = platform_specific_verify_command('file')
93
93
  Chef::Resource::File::Verification.new(parent_resource, test_command, {})
94
94
  .verify(temp_path)
@@ -30,24 +30,28 @@ describe Chef::Resource::PowershellScript do
30
30
  run_context = Chef::RunContext.new(node, nil, nil)
31
31
 
32
32
  @resource = Chef::Resource::PowershellScript.new("powershell_unit_test", run_context)
33
-
34
33
  end
35
34
 
36
- it "should create a new Chef::Resource::PowershellScript" do
35
+ it "creates a new Chef::Resource::PowershellScript" do
37
36
  expect(@resource).to be_a_kind_of(Chef::Resource::PowershellScript)
38
37
  end
39
38
 
40
- it "should set convert_boolean_return to false by default" do
39
+ it "sets convert_boolean_return to false by default" do
41
40
  expect(@resource.convert_boolean_return).to eq(false)
42
41
  end
43
42
 
44
- it "should return the value for convert_boolean_return that was set" do
43
+ it "returns the value for convert_boolean_return that was set" do
45
44
  @resource.convert_boolean_return true
46
45
  expect(@resource.convert_boolean_return).to eq(true)
47
46
  @resource.convert_boolean_return false
48
47
  expect(@resource.convert_boolean_return).to eq(false)
49
48
  end
50
49
 
50
+ it "raises an error when architecture is i386 on Windows Nano Server" do
51
+ allow(Chef::Platform).to receive(:windows_nano_server?).and_return(true)
52
+ expect{@resource.architecture(:i386)}.to raise_error(Chef::Exceptions::Win32ArchitectureIncorrect, "cannot execute script with requested architecture 'i386' on Windows Nano Server")
53
+ end
54
+
51
55
  context "when using guards" do
52
56
  let(:resource) { @resource }
53
57
  before(:each) do
@@ -62,32 +66,32 @@ describe Chef::Resource::PowershellScript do
62
66
  expect(inherited_difference).to eq([])
63
67
  end
64
68
 
65
- it "should allow guard interpreter to be set to Chef::Resource::Script" do
69
+ it "allows guard interpreter to be set to Chef::Resource::Script" do
66
70
  resource.guard_interpreter(:script)
67
71
  allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:evaluate_action).and_return(false)
68
72
  resource.only_if("echo hi")
69
73
  end
70
74
 
71
- it "should allow guard interpreter to be set to Chef::Resource::Bash derived from Chef::Resource::Script" do
75
+ it "allows guard interpreter to be set to Chef::Resource::Bash derived from Chef::Resource::Script" do
72
76
  resource.guard_interpreter(:bash)
73
77
  allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:evaluate_action).and_return(false)
74
78
  resource.only_if("echo hi")
75
79
  end
76
80
 
77
- it "should allow guard interpreter to be set to Chef::Resource::PowershellScript derived indirectly from Chef::Resource::Script" do
81
+ it "allows guard interpreter to be set to Chef::Resource::PowershellScript derived indirectly from Chef::Resource::Script" do
78
82
  resource.guard_interpreter(:powershell_script)
79
83
  allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:evaluate_action).and_return(false)
80
84
  resource.only_if("echo hi")
81
85
  end
82
86
 
83
- it "should enable convert_boolean_return by default for guards in the context of powershell_script when no guard params are specified" do
87
+ it "enables convert_boolean_return by default for guards in the context of powershell_script when no guard params are specified" do
84
88
  allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:evaluate_action).and_return(true)
85
89
  allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:block_from_attributes).with(
86
90
  {:convert_boolean_return => true, :code => "$true"}).and_return(Proc.new {})
87
91
  resource.only_if("$true")
88
92
  end
89
93
 
90
- it "should enable convert_boolean_return by default for guards in non-Chef::Resource::Script derived resources when no guard params are specified" do
94
+ it "enables convert_boolean_return by default for guards in non-Chef::Resource::Script derived resources when no guard params are specified" do
91
95
  node = Chef::Node.new
92
96
  run_context = Chef::RunContext.new(node, nil, nil)
93
97
  file_resource = Chef::Resource::File.new('idontexist', run_context)
@@ -98,21 +102,21 @@ describe Chef::Resource::PowershellScript do
98
102
  resource.only_if("$true")
99
103
  end
100
104
 
101
- it "should enable convert_boolean_return by default for guards in the context of powershell_script when guard params are specified" do
105
+ it "enables convert_boolean_return by default for guards in the context of powershell_script when guard params are specified" do
102
106
  guard_parameters = {:cwd => '/etc/chef', :architecture => :x86_64}
103
107
  allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:block_from_attributes).with(
104
108
  {:convert_boolean_return => true, :code => "$true"}.merge(guard_parameters)).and_return(Proc.new {})
105
109
  resource.only_if("$true", guard_parameters)
106
110
  end
107
111
 
108
- it "should pass convert_boolean_return as true if it was specified as true in a guard parameter" do
112
+ it "passes convert_boolean_return as true if it was specified as true in a guard parameter" do
109
113
  guard_parameters = {:cwd => '/etc/chef', :convert_boolean_return => true, :architecture => :x86_64}
110
114
  allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:block_from_attributes).with(
111
115
  {:convert_boolean_return => true, :code => "$true"}.merge(guard_parameters)).and_return(Proc.new {})
112
116
  resource.only_if("$true", guard_parameters)
113
117
  end
114
118
 
115
- it "should pass convert_boolean_return as false if it was specified as true in a guard parameter" do
119
+ it "passes convert_boolean_return as false if it was specified as true in a guard parameter" do
116
120
  other_guard_parameters = {:cwd => '/etc/chef', :architecture => :x86_64}
117
121
  parameters_with_boolean_disabled = other_guard_parameters.merge({:convert_boolean_return => false, :code => "$true"})
118
122
  allow_any_instance_of(Chef::GuardInterpreter::ResourceGuardInterpreter).to receive(:block_from_attributes).with(
@@ -127,6 +131,6 @@ describe Chef::Resource::PowershellScript do
127
131
  let(:resource_name) { :powershell_script }
128
132
  let(:interpreter_file_name) { 'powershell.exe' }
129
133
 
130
- it_should_behave_like "a Windows script resource"
134
+ it_behaves_like "a Windows script resource"
131
135
  end
132
136
  end
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # Author:: AJ Christensen (<aj@hjksolutions.com>)
3
3
  # Author:: Tyler Cloke (<tyler@opscode.com>)
4
- # Copyright:: Copyright (c) 2008 Opscode, Inc.
4
+ # Copyright:: Copyright (c) 2008-2015 Chef Software, Inc.
5
5
  # License:: Apache License, Version 2.0
6
6
  #
7
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -139,14 +139,14 @@ describe Chef::Resource::Service do
139
139
  expect { @resource.send(attrib, "poop") }.to raise_error(ArgumentError)
140
140
  end
141
141
 
142
- it "should default all the feature support to false" do
143
- support_hash = { :status => false, :restart => false, :reload=> false }
142
+ it "should default all the feature support to nil" do
143
+ support_hash = { :status => nil, :restart => nil, :reload=> nil }
144
144
  expect(@resource.supports).to eq(support_hash)
145
145
  end
146
146
 
147
147
  it "should allow you to set what features this resource supports as a array" do
148
148
  support_array = [ :status, :restart ]
149
- support_hash = { :status => true, :restart => true, :reload => false }
149
+ support_hash = { :status => true, :restart => true, :reload => nil }
150
150
  @resource.supports(support_array)
151
151
  expect(@resource.supports).to eq(support_hash)
152
152
  end
@@ -54,6 +54,10 @@ describe Chef::Resource::Subversion do
54
54
  expect(@svn.svn_arguments).to eq('--no-auth-cache')
55
55
  end
56
56
 
57
+ it "sets svn binary to nil by default" do
58
+ expect(@svn.svn_binary).to be_nil
59
+ end
60
+
57
61
  it "resets svn arguments to nil when given false in the setter" do
58
62
  @svn.svn_arguments(false)
59
63
  expect(@svn.svn_arguments).to be_nil
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: AJ Christensen (<aj@opscode.com>)
3
- # Copyright:: Copyright (c) 2008 Opscode, Inc.
3
+ # Copyright:: Copyright (c) 2008-2015 Chef Software, Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -78,3 +78,12 @@ describe Chef::Resource::YumPackage, "allow_downgrade" do
78
78
  expect { @resource.allow_downgrade "monkey" }.to raise_error(ArgumentError)
79
79
  end
80
80
  end
81
+
82
+ describe Chef::Resource::YumPackage, "yum_binary" do
83
+ let(:resource) { Chef::Resource::YumPackage.new("foo") }
84
+
85
+ it "should allow you to specify the yum_binary" do
86
+ resource.yum_binary "/usr/bin/yum-something"
87
+ expect(resource.yum_binary).to eql("/usr/bin/yum-something")
88
+ end
89
+ end
@@ -187,4 +187,9 @@ describe Chef::RunList::VersionedRecipeList do
187
187
  end
188
188
  end
189
189
 
190
+ context "with duplicated names", :chef_gte_13_only do
191
+ it "should fail in Chef 13" do
192
+ expect(list).to_not respond_to(:with_duplicate_names)
193
+ end
194
+ end
190
195
  end
@@ -0,0 +1,394 @@
1
+ #
2
+ # Author:: Prajakta Purohit (prajakta@opscode.com)
3
+ # Copyright:: Copyright (c) 2012 Opscode, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'spec_helper'
20
+
21
+ describe Chef::Win32::Registry do
22
+ include_context "Win32"
23
+
24
+ let(:value1) { { :name => "one", :type => :string, :data => "1" } }
25
+ let(:value1_upcase_name) { {:name => "ONE", :type => :string, :data => "1"} }
26
+ let(:key_path) { 'HKCU\Software\OpscodeNumbers' }
27
+ let(:key) { 'Software\OpscodeNumbers' }
28
+ let(:key_parent) { 'Software' }
29
+ let(:key_to_delete) { 'OpscodeNumbers' }
30
+ let(:sub_key) {'OpscodePrimes'}
31
+ let(:missing_key_path) {'HKCU\Software'}
32
+ let(:registry) { Chef::Win32::Registry.new() }
33
+ let(:hive_mock) { double("::Win32::Registry::KHKEY_CURRENT_USER") }
34
+ let(:reg_mock) { double("reg") }
35
+
36
+ before(:all) do
37
+ Win32::Registry = Class.new
38
+ Win32::Registry::Error = Class.new(RuntimeError)
39
+ end
40
+
41
+ before(:each) do
42
+ allow_any_instance_of(Chef::Win32::Registry).to receive(:machine_architecture).and_return(:x86_64)
43
+
44
+ #Making the values for registry constants available on unix
45
+ Win32::Registry::KEY_SET_VALUE = 0x0002
46
+ Win32::Registry::KEY_QUERY_VALUE = 0x0001
47
+ Win32::Registry::KEY_WRITE = 0x00020000 | 0x0002 | 0x0004
48
+ Win32::Registry::KEY_READ = 0x00020000 | 0x0001 | 0x0008 | 0x0010
49
+ end
50
+
51
+ after(:each) do
52
+ Win32::Registry.send(:remove_const, 'KEY_SET_VALUE') if defined?(Win32::Registry::KEY_SET_VALUE)
53
+ Win32::Registry.send(:remove_const, 'KEY_QUERY_VALUE') if defined?(Win32::Registry::KEY_QUERY_VALUE)
54
+ Win32::Registry.send(:remove_const, 'KEY_READ') if defined?(Win32::Registry::KEY_READ)
55
+ Win32::Registry.send(:remove_const, 'KEY_WRITE') if defined?(Win32::Registry::KEY_WRITE)
56
+ end
57
+
58
+ describe "get_values" do
59
+ it "gets all values for a key if the key exists" do
60
+ expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
61
+ expect(registry).to receive(:key_exists!).with(key_path).and_return(true)
62
+ expect(hive_mock).to receive(:open).with(key, ::Win32::Registry::KEY_READ | registry.registry_system_architecture).and_yield(reg_mock)
63
+ expect(reg_mock).to receive(:map)
64
+ registry.get_values(key_path)
65
+ end
66
+
67
+ it "throws an exception if key does not exist" do
68
+ expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
69
+ expect(registry).to receive(:key_exists!).with(key_path).and_raise(Chef::Exceptions::Win32RegKeyMissing)
70
+ expect{registry.get_values(key_path)}.to raise_error(Chef::Exceptions::Win32RegKeyMissing)
71
+ end
72
+ end
73
+
74
+ describe "set_value" do
75
+ it "does nothing if key and hive and value exist" do
76
+ expect(registry).to receive(:key_exists!).with(key_path).and_return(true)
77
+ expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
78
+ expect(registry).to receive(:value_exists?).with(key_path, value1).and_return(true)
79
+ expect(registry).to receive(:data_exists?).with(key_path, value1).and_return(true)
80
+ registry.set_value(key_path, value1)
81
+ end
82
+ it "does nothing if case insensitive key and hive and value exist" do
83
+ expect(registry).to receive(:key_exists!).with(key_path.downcase).and_return(true)
84
+ expect(registry).to receive(:get_hive_and_key).with(key_path.downcase).and_return([hive_mock, key])
85
+ expect(registry).to receive(:value_exists?).with(key_path.downcase, value1).and_return(true)
86
+ expect(registry).to receive(:data_exists?).with(key_path.downcase, value1).and_return(true)
87
+ registry.set_value(key_path.downcase, value1)
88
+ end
89
+ it "does nothing if key and hive and value with a case insensitive name exist" do
90
+ expect(registry).to receive(:key_exists!).with(key_path.downcase).and_return(true)
91
+ expect(registry).to receive(:get_hive_and_key).with(key_path.downcase).and_return([hive_mock, key])
92
+ expect(registry).to receive(:value_exists?).with(key_path.downcase, value1_upcase_name).and_return(true)
93
+ expect(registry).to receive(:data_exists?).with(key_path.downcase, value1_upcase_name).and_return(true)
94
+ registry.set_value(key_path.downcase, value1_upcase_name)
95
+ end
96
+ it "updates value if key and hive and value exist, but data is different" do
97
+ expect(registry).to receive(:key_exists!).with(key_path).and_return(true)
98
+ expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
99
+ expect(registry).to receive(:value_exists?).with(key_path, value1).and_return(true)
100
+ expect(registry).to receive(:data_exists?).with(key_path, value1).and_return(false)
101
+ expect(hive_mock).to receive(:open).with(key, Win32::Registry::KEY_SET_VALUE | ::Win32::Registry::KEY_QUERY_VALUE | registry.registry_system_architecture).and_yield(reg_mock)
102
+ expect(registry).to receive(:get_type_from_name).with(:string).and_return(1)
103
+ expect(reg_mock).to receive(:write).with("one", 1, "1")
104
+ registry.set_value(key_path, value1)
105
+ end
106
+
107
+ it "creates value if the key exists and the value does not exist" do
108
+ expect(registry).to receive(:key_exists!).with(key_path).and_return(true)
109
+ expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
110
+ expect(registry).to receive(:value_exists?).with(key_path, value1).and_return(false)
111
+ expect(hive_mock).to receive(:open).with(key, ::Win32::Registry::KEY_SET_VALUE | ::Win32::Registry::KEY_QUERY_VALUE | registry.registry_system_architecture).and_yield(reg_mock)
112
+ expect(registry).to receive(:get_type_from_name).with(:string).and_return(1)
113
+ expect(reg_mock).to receive(:write).with("one", 1, "1")
114
+ registry.set_value(key_path, value1)
115
+ end
116
+
117
+ it "should raise an exception if the key does not exist" do
118
+ expect(registry).to receive(:key_exists!).with(key_path).and_raise(Chef::Exceptions::Win32RegKeyMissing)
119
+ expect {registry.set_value(key_path, value1)}.to raise_error(Chef::Exceptions::Win32RegKeyMissing)
120
+ end
121
+ end
122
+
123
+ describe "delete_value" do
124
+ it "deletes value if value exists" do
125
+ expect(registry).to receive(:value_exists?).with(key_path, value1).and_return(true)
126
+ expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
127
+ expect(hive_mock).to receive(:open).with(key, ::Win32::Registry::KEY_SET_VALUE | registry.registry_system_architecture).and_yield(reg_mock)
128
+ expect(reg_mock).to receive(:delete_value).with("one").and_return(true)
129
+ registry.delete_value(key_path, value1)
130
+ end
131
+
132
+ it "raises an exception if the key does not exist" do
133
+ expect(registry).to receive(:value_exists?).with(key_path, value1).and_return(true)
134
+ expect(registry).to receive(:get_hive_and_key).with(key_path).and_raise(Chef::Exceptions::Win32RegKeyMissing)
135
+ registry.delete_value(key_path, value1)
136
+ end
137
+
138
+ it "does nothing if the value does not exist" do
139
+ expect(registry).to receive(:value_exists?).with(key_path, value1).and_return(false)
140
+ registry.delete_value(key_path, value1)
141
+ end
142
+ end
143
+
144
+ describe "create_key" do
145
+ it "creates key if intermediate keys are missing and recursive is set to true" do
146
+ expect(registry).to receive(:keys_missing?).with(key_path).and_return(true)
147
+ expect(registry).to receive(:create_missing).with(key_path)
148
+ expect(registry).to receive(:key_exists?).with(key_path).and_return(false)
149
+ expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
150
+ expect(hive_mock).to receive(:create).with(key, ::Win32::Registry::KEY_WRITE | registry.registry_system_architecture)
151
+ registry.create_key(key_path, true)
152
+ end
153
+
154
+ it "raises an exception if intermediate keys are missing and recursive is set to false" do
155
+ expect(registry).to receive(:keys_missing?).with(key_path).and_return(true)
156
+ expect{registry.create_key(key_path, false)}.to raise_error(Chef::Exceptions::Win32RegNoRecursive)
157
+ end
158
+
159
+ it "does nothing if the key exists" do
160
+ expect(registry).to receive(:keys_missing?).with(key_path).and_return(true)
161
+ expect(registry).to receive(:create_missing).with(key_path)
162
+ expect(registry).to receive(:key_exists?).with(key_path).and_return(true)
163
+ registry.create_key(key_path, true)
164
+ end
165
+
166
+ it "create key if intermediate keys not missing and recursive is set to false" do
167
+ expect(registry).to receive(:keys_missing?).with(key_path).and_return(false)
168
+ expect(registry).to receive(:key_exists?).with(key_path).and_return(false)
169
+ expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
170
+ expect(hive_mock).to receive(:create).with(key, ::Win32::Registry::KEY_WRITE | registry.registry_system_architecture)
171
+ registry.create_key(key_path, false)
172
+ end
173
+
174
+ it "create key if intermediate keys not missing and recursive is set to true" do
175
+ expect(registry).to receive(:keys_missing?).with(key_path).and_return(false)
176
+ expect(registry).to receive(:key_exists?).with(key_path).and_return(false)
177
+ expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
178
+ expect(hive_mock).to receive(:create).with(key, ::Win32::Registry::KEY_WRITE | registry.registry_system_architecture)
179
+ registry.create_key(key_path, true)
180
+ end
181
+ end
182
+
183
+ describe "delete_key", :windows_only do
184
+ it "deletes key if it has subkeys and recursive is set to true" do
185
+ expect(registry).to receive(:key_exists?).with(key_path).and_return(true)
186
+ expect(registry).to receive(:has_subkeys?).with(key_path).and_return(true)
187
+ expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
188
+ expect(hive_mock).to receive(:open).with(key_parent, ::Win32::Registry::KEY_WRITE | registry.registry_system_architecture).and_yield(reg_mock)
189
+ expect(reg_mock).to receive(:delete_key).with(key_to_delete, true).and_return(true)
190
+ registry.delete_key(key_path, true)
191
+ end
192
+
193
+ it "raises an exception if it has subkeys but recursive is set to false" do
194
+ expect(registry).to receive(:key_exists?).with(key_path).and_return(true)
195
+ expect(registry).to receive(:has_subkeys?).with(key_path).and_return(true)
196
+ expect{registry.delete_key(key_path, false)}.to raise_error(Chef::Exceptions::Win32RegNoRecursive)
197
+ end
198
+
199
+ it "deletes key if the key exists and has no subkeys" do
200
+ expect(registry).to receive(:key_exists?).with(key_path).and_return(true)
201
+ expect(registry).to receive(:has_subkeys?).with(key_path).and_return(false)
202
+ expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
203
+ expect(hive_mock).to receive(:open).with(key_parent, ::Win32::Registry::KEY_WRITE | registry.registry_system_architecture).and_yield(reg_mock)
204
+ expect(reg_mock).to receive(:delete_key).with(key_to_delete, true).and_return(true)
205
+ registry.delete_key(key_path, true)
206
+ end
207
+ end
208
+
209
+ describe "key_exists?" do
210
+ it "returns true if key_exists" do
211
+ expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
212
+ expect(hive_mock).to receive(:open).with(key, ::Win32::Registry::KEY_READ | registry.registry_system_architecture).and_yield(reg_mock)
213
+ expect(registry.key_exists?(key_path)).to eq(true)
214
+ end
215
+
216
+ it "returns false if key does not exist" do
217
+ expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
218
+ expect(hive_mock).to receive(:open).with(key, ::Win32::Registry::KEY_READ | registry.registry_system_architecture).and_raise(::Win32::Registry::Error)
219
+ expect(registry.key_exists?(key_path)).to eq(false)
220
+ end
221
+ end
222
+
223
+ describe "key_exists!" do
224
+ it "throws an exception if the key_parent does not exist" do
225
+ expect(registry).to receive(:key_exists?).with(key_path).and_return(false)
226
+ expect{registry.key_exists!(key_path)}.to raise_error(Chef::Exceptions::Win32RegKeyMissing)
227
+ end
228
+ end
229
+
230
+ describe "hive_exists?" do
231
+ it "returns true if the hive exists" do
232
+ expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
233
+ registry.hive_exists?(key_path) == true
234
+ end
235
+
236
+ it "returns false if the hive does not exist" do
237
+ expect(registry).to receive(:get_hive_and_key).with(key_path).and_raise(Chef::Exceptions::Win32RegHiveMissing)
238
+ registry.hive_exists?(key_path) == false
239
+ end
240
+ end
241
+
242
+ describe "has_subkeys?" do
243
+ it "returns true if the key has subkeys" do
244
+ expect(registry).to receive(:key_exists!).with(key_path).and_return(true)
245
+ expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
246
+ expect(hive_mock).to receive(:open).with(key, ::Win32::Registry::KEY_READ | registry.registry_system_architecture).and_yield(reg_mock)
247
+ expect(reg_mock).to receive(:each_key).and_yield(key)
248
+ registry.has_subkeys?(key_path) == true
249
+ end
250
+
251
+ it "returns false if the key does not have subkeys" do
252
+ expect(registry).to receive(:key_exists!).with(key_path).and_return(true)
253
+ expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
254
+ expect(hive_mock).to receive(:open).with(key, ::Win32::Registry::KEY_READ | registry.registry_system_architecture).and_yield(reg_mock)
255
+ expect(reg_mock).to receive(:each_key).and_return(no_args())
256
+ expect(registry.has_subkeys?(key_path)).to eq(false)
257
+ end
258
+
259
+ it "throws an exception if the key does not exist" do
260
+ expect(registry).to receive(:key_exists!).with(key_path).and_raise(Chef::Exceptions::Win32RegKeyMissing)
261
+ expect {registry.set_value(key_path, value1)}.to raise_error(Chef::Exceptions::Win32RegKeyMissing)
262
+ end
263
+ end
264
+
265
+ describe "get_subkeys" do
266
+ it "returns the subkeys if they exist" do
267
+ expect(registry).to receive(:key_exists!).with(key_path).and_return(true)
268
+ expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
269
+ expect(hive_mock).to receive(:open).with(key, ::Win32::Registry::KEY_READ | registry.registry_system_architecture).and_yield(reg_mock)
270
+ expect(reg_mock).to receive(:each_key).and_yield(sub_key)
271
+ registry.get_subkeys(key_path)
272
+ end
273
+ end
274
+
275
+ describe "value_exists?" do
276
+ it "throws an exception if the key does not exist" do
277
+ expect(registry).to receive(:key_exists!).with(key_path).and_raise(Chef::Exceptions::Win32RegKeyMissing)
278
+ expect {registry.value_exists?(key_path, value1)}.to raise_error(Chef::Exceptions::Win32RegKeyMissing)
279
+ end
280
+
281
+ it "returns true if the value exists" do
282
+ expect(registry).to receive(:key_exists!).with(key_path).and_return(true)
283
+ expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
284
+ expect(hive_mock).to receive(:open).with(key, ::Win32::Registry::KEY_READ | registry.registry_system_architecture).and_yield(reg_mock)
285
+ expect(reg_mock).to receive(:any?).and_yield("one")
286
+ registry.value_exists?(key_path, value1) == true
287
+ end
288
+
289
+ it "returns false if the value does not exist" do
290
+ expect(registry).to receive(:key_exists!).with(key_path).and_return(true)
291
+ expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
292
+ expect(hive_mock).to receive(:open).with(key, ::Win32::Registry::KEY_READ | registry.registry_system_architecture).and_yield(reg_mock)
293
+ expect(reg_mock).to receive(:any?).and_yield(no_args())
294
+ registry.value_exists?(key_path, value1) == false
295
+ end
296
+ end
297
+
298
+ describe "data_exists?" do
299
+ it "throws an exception if the key does not exist" do
300
+ expect(registry).to receive(:key_exists!).with(key_path).and_raise(Chef::Exceptions::Win32RegKeyMissing)
301
+ expect {registry.data_exists?(key_path, value1)}.to raise_error(Chef::Exceptions::Win32RegKeyMissing)
302
+ end
303
+
304
+ it "returns true if the data exists" do
305
+ expect(registry).to receive(:key_exists!).with(key_path).and_return(true)
306
+ expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
307
+ expect(registry).to receive(:get_type_from_name).with(:string).and_return(1)
308
+ expect(reg_mock).to receive(:each).with(no_args()).and_yield("one", 1, "1")
309
+ expect(hive_mock).to receive(:open).with(key, ::Win32::Registry::KEY_READ | registry.registry_system_architecture).and_yield(reg_mock)
310
+ expect(registry.data_exists?(key_path, value1)).to eq(true)
311
+ end
312
+
313
+ it "returns false if the data does not exist" do
314
+ expect(registry).to receive(:key_exists!).with(key_path).and_return(true)
315
+ expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
316
+ expect(hive_mock).to receive(:open).with(key, ::Win32::Registry::KEY_READ | registry.registry_system_architecture).and_yield(reg_mock)
317
+ expect(registry).to receive(:get_type_from_name).with(:string).and_return(1)
318
+ expect(reg_mock).to receive(:each).with(no_args()).and_yield("one", 1, "2")
319
+ expect(registry.data_exists?(key_path, value1)).to eq(false)
320
+ end
321
+ end
322
+
323
+ describe "value_exists!" do
324
+ it "does nothing if the value exists" do
325
+ expect(registry).to receive(:value_exists?).with(key_path, value1).and_return(true)
326
+ registry.value_exists!(key_path, value1)
327
+ end
328
+
329
+ it "throws an exception if the value does not exist" do
330
+ expect(registry).to receive(:value_exists?).with(key_path, value1).and_return(false)
331
+ expect{registry.value_exists!(key_path, value1)}.to raise_error(Chef::Exceptions::Win32RegValueMissing)
332
+ end
333
+ end
334
+
335
+ describe "data_exists!" do
336
+ it "does nothing if the data exists" do
337
+ expect(registry).to receive(:data_exists?).with(key_path, value1).and_return(true)
338
+ registry.data_exists!(key_path, value1)
339
+ end
340
+
341
+ it "throws an exception if the data does not exist" do
342
+ expect(registry).to receive(:data_exists?).with(key_path, value1).and_return(false)
343
+ expect{registry.data_exists!(key_path, value1)}.to raise_error(Chef::Exceptions::Win32RegDataMissing)
344
+ end
345
+ end
346
+
347
+ describe "type_matches?" do
348
+ it "returns true if type matches" do
349
+ expect(registry).to receive(:value_exists!).with(key_path, value1).and_return(true)
350
+ expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
351
+ expect(hive_mock).to receive(:open).with(key, ::Win32::Registry::KEY_READ | registry.registry_system_architecture).and_yield(reg_mock)
352
+ expect(registry).to receive(:get_type_from_name).with(:string).and_return(1)
353
+ expect(reg_mock).to receive(:each).and_yield("one", 1)
354
+ expect(registry.type_matches?(key_path, value1)).to eq(true)
355
+ end
356
+
357
+ it "returns false if type does not match" do
358
+ expect(registry).to receive(:value_exists!).with(key_path, value1).and_return(true)
359
+ expect(registry).to receive(:get_hive_and_key).with(key_path).and_return([hive_mock, key])
360
+ expect(hive_mock).to receive(:open).with(key, ::Win32::Registry::KEY_READ | registry.registry_system_architecture).and_yield(reg_mock)
361
+ expect(reg_mock).to receive(:each).and_yield("two", 2)
362
+ expect(registry.type_matches?(key_path, value1)).to eq(false)
363
+ end
364
+
365
+ it "throws an exception if value does not exist" do
366
+ expect(registry).to receive(:value_exists?).with(key_path, value1).and_return(false)
367
+ expect{registry.type_matches?(key_path, value1)}.to raise_error(Chef::Exceptions::Win32RegValueMissing)
368
+ end
369
+ end
370
+
371
+ describe "type_matches!" do
372
+ it "does nothing if the type_matches" do
373
+ expect(registry).to receive(:type_matches?).with(key_path, value1).and_return(true)
374
+ registry.type_matches!(key_path, value1)
375
+ end
376
+
377
+ it "throws an exception if the type does not match" do
378
+ expect(registry).to receive(:type_matches?).with(key_path, value1).and_return(false)
379
+ expect{registry.type_matches!(key_path, value1)}.to raise_error(Chef::Exceptions::Win32RegTypesMismatch)
380
+ end
381
+ end
382
+
383
+ describe "keys_missing?" do
384
+ it "returns true if the keys are missing" do
385
+ expect(registry).to receive(:key_exists?).with(missing_key_path).and_return(false)
386
+ expect(registry.keys_missing?(key_path)).to eq(true)
387
+ end
388
+
389
+ it "returns false if no keys in the path are missing" do
390
+ expect(registry).to receive(:key_exists?).with(missing_key_path).and_return(true)
391
+ expect(registry.keys_missing?(key_path)).to eq(false)
392
+ end
393
+ end
394
+ end