chef 12.4.3-universal-mingw32 → 12.5.1-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (320) 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 +4 -110
  6. data/bin/chef-service-manager +3 -1
  7. data/distro/common/html/knife_cookbook_site.html +18 -18
  8. data/distro/common/man/man1/knife-cookbook-site.1 +11 -11
  9. data/lib/chef.rb +1 -1
  10. data/lib/chef/application.rb +1 -1
  11. data/lib/chef/application/apply.rb +19 -1
  12. data/lib/chef/application/client.rb +11 -5
  13. data/lib/chef/application/knife.rb +2 -2
  14. data/lib/chef/application/solo.rb +1 -1
  15. data/lib/chef/application/windows_service_manager.rb +19 -12
  16. data/lib/chef/chef_class.rb +46 -0
  17. data/lib/chef/chef_fs/config.rb +22 -24
  18. data/lib/chef/chef_fs/data_handler/client_data_handler.rb +3 -1
  19. data/lib/chef/chef_fs/file_pattern.rb +4 -15
  20. data/lib/chef/chef_fs/file_system/acl_dir.rb +3 -4
  21. data/lib/chef/chef_fs/file_system/acls_dir.rb +5 -1
  22. data/lib/chef/chef_fs/file_system/base_fs_dir.rb +0 -5
  23. data/lib/chef/chef_fs/file_system/base_fs_object.rb +5 -2
  24. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb +2 -9
  25. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_entry.rb +2 -9
  26. data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbooks_dir.rb +10 -17
  27. data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +1 -12
  28. data/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb +15 -11
  29. data/lib/chef/chef_fs/file_system/chef_server_root_dir.rb +8 -2
  30. data/lib/chef/chef_fs/file_system/cookbook_dir.rb +4 -4
  31. data/lib/chef/chef_fs/file_system/cookbooks_acl_dir.rb +1 -1
  32. data/lib/chef/chef_fs/file_system/cookbooks_dir.rb +3 -11
  33. data/lib/chef/chef_fs/file_system/data_bags_dir.rb +3 -5
  34. data/lib/chef/chef_fs/file_system/environments_dir.rb +1 -1
  35. data/lib/chef/chef_fs/file_system/file_system_entry.rb +7 -4
  36. data/lib/chef/chef_fs/file_system/memory_dir.rb +2 -3
  37. data/lib/chef/chef_fs/file_system/multiplexed_dir.rb +15 -0
  38. data/lib/chef/chef_fs/file_system/nodes_dir.rb +1 -1
  39. data/lib/chef/chef_fs/file_system/organization_members_entry.rb +2 -2
  40. data/lib/chef/chef_fs/file_system/rest_list_dir.rb +4 -9
  41. data/lib/chef/chef_fs/knife.rb +35 -7
  42. data/lib/chef/chef_fs/path_utils.rb +65 -34
  43. data/lib/chef/client.rb +2 -3
  44. data/lib/chef/config.rb +34 -2
  45. data/lib/chef/{mixin/wstring.rb → constants.rb} +9 -13
  46. data/lib/chef/cookbook/metadata.rb +25 -3
  47. data/lib/chef/cookbook/synchronizer.rb +1 -1
  48. data/lib/chef/cookbook_site_streaming_uploader.rb +1 -1
  49. data/lib/chef/cookbook_version.rb +3 -3
  50. data/lib/chef/delayed_evaluator.rb +21 -0
  51. data/lib/chef/deprecation/mixin/template.rb +1 -2
  52. data/lib/chef/deprecation/provider/cookbook_file.rb +1 -1
  53. data/lib/chef/deprecation/provider/file.rb +1 -1
  54. data/lib/chef/deprecation/provider/remote_directory.rb +52 -0
  55. data/lib/chef/deprecation/provider/remote_file.rb +1 -2
  56. data/lib/chef/deprecation/provider/template.rb +1 -1
  57. data/lib/chef/deprecation/warnings.rb +3 -4
  58. data/lib/chef/dsl/reboot_pending.rb +3 -2
  59. data/lib/chef/dsl/recipe.rb +26 -7
  60. data/lib/chef/dsl/resources.rb +2 -2
  61. data/lib/chef/event_dispatch/base.rb +51 -22
  62. data/lib/chef/event_dispatch/dispatcher.rb +21 -6
  63. data/lib/chef/event_dispatch/dsl.rb +64 -0
  64. data/lib/chef/exceptions.rb +28 -1
  65. data/lib/chef/file_content_management/tempfile.rb +1 -1
  66. data/lib/chef/formatters/base.rb +3 -0
  67. data/lib/chef/formatters/doc.rb +56 -6
  68. data/lib/chef/formatters/error_inspectors/compile_error_inspector.rb +36 -0
  69. data/lib/chef/formatters/minimal.rb +2 -2
  70. data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +3 -1
  71. data/lib/chef/http/http_request.rb +1 -1
  72. data/lib/chef/knife.rb +35 -55
  73. data/lib/chef/knife/bootstrap.rb +41 -0
  74. data/lib/chef/knife/bootstrap/chef_vault_handler.rb +1 -0
  75. data/lib/chef/knife/bootstrap/client_builder.rb +16 -0
  76. data/lib/chef/knife/bootstrap/templates/README.md +3 -4
  77. data/lib/chef/knife/bootstrap/templates/chef-full.erb +1 -1
  78. data/lib/chef/knife/cookbook_create.rb +1 -1
  79. data/lib/chef/knife/cookbook_site_download.rb +1 -1
  80. data/lib/chef/knife/cookbook_site_install.rb +1 -1
  81. data/lib/chef/knife/cookbook_site_share.rb +6 -6
  82. data/lib/chef/knife/cookbook_site_unshare.rb +2 -2
  83. data/lib/chef/knife/core/bootstrap_context.rb +12 -4
  84. data/lib/chef/knife/core/custom_manifest_loader.rb +69 -0
  85. data/lib/chef/knife/core/gem_glob_loader.rb +138 -0
  86. data/lib/chef/knife/core/hashed_command_loader.rb +80 -0
  87. data/lib/chef/knife/core/node_presenter.rb +24 -1
  88. data/lib/chef/knife/core/object_loader.rb +1 -0
  89. data/lib/chef/knife/core/subcommand_loader.rb +131 -146
  90. data/lib/chef/knife/node_run_list_remove.rb +12 -1
  91. data/lib/chef/knife/null.rb +10 -0
  92. data/lib/chef/knife/rehash.rb +62 -0
  93. data/lib/chef/knife/search.rb +3 -3
  94. data/lib/chef/knife/ssh.rb +52 -30
  95. data/lib/chef/knife/ssl_check.rb +3 -2
  96. data/lib/chef/knife/user_edit.rb +1 -2
  97. data/lib/chef/local_mode.rb +5 -0
  98. data/lib/chef/log.rb +5 -1
  99. data/lib/chef/mixin/deprecation.rb +8 -8
  100. data/lib/chef/mixin/params_validate.rb +362 -135
  101. data/lib/chef/mixin/template.rb +48 -0
  102. data/lib/chef/mixin/which.rb +1 -1
  103. data/lib/chef/mixin/wide_string.rb +72 -0
  104. data/lib/chef/mixin/windows_architecture_helper.rb +15 -39
  105. data/lib/chef/mixin/windows_env_helper.rb +4 -1
  106. data/lib/chef/monkey_patches/webrick-utils.rb +51 -0
  107. data/lib/chef/monkey_patches/win32/registry.rb +72 -0
  108. data/lib/chef/node.rb +116 -3
  109. data/lib/chef/node_map.rb +2 -2
  110. data/lib/chef/platform/handler_map.rb +0 -5
  111. data/lib/chef/platform/provider_mapping.rb +5 -6
  112. data/lib/chef/platform/query_helpers.rb +46 -4
  113. data/lib/chef/platform/rebooter.rb +1 -1
  114. data/lib/chef/platform/service_helpers.rb +30 -32
  115. data/lib/chef/policy_builder.rb +1 -8
  116. data/lib/chef/policy_builder/dynamic.rb +186 -0
  117. data/lib/chef/policy_builder/expand_node_object.rb +30 -15
  118. data/lib/chef/policy_builder/policyfile.rb +155 -18
  119. data/lib/chef/property.rb +568 -0
  120. data/lib/chef/provider.rb +222 -13
  121. data/lib/chef/provider/batch.rb +8 -0
  122. data/lib/chef/provider/deploy.rb +5 -7
  123. data/lib/chef/provider/directory.rb +14 -2
  124. data/lib/chef/provider/dsc_resource.rb +5 -9
  125. data/lib/chef/provider/group/pw.rb +1 -1
  126. data/lib/chef/provider/ifconfig.rb +2 -2
  127. data/lib/chef/provider/lwrp_base.rb +1 -75
  128. data/lib/chef/provider/mount.rb +7 -3
  129. data/lib/chef/provider/package.rb +1 -1
  130. data/lib/chef/provider/package/dpkg.rb +5 -11
  131. data/lib/chef/provider/package/rpm.rb +2 -2
  132. data/lib/chef/provider/package/rubygems.rb +1 -1
  133. data/lib/chef/provider/package/windows/msi.rb +2 -2
  134. data/lib/chef/provider/package/yum.rb +17 -5
  135. data/lib/chef/provider/powershell_script.rb +59 -23
  136. data/lib/chef/provider/registry_key.rb +5 -5
  137. data/lib/chef/provider/remote_directory.rb +190 -102
  138. data/lib/chef/provider/service.rb +12 -2
  139. data/lib/chef/provider/service/aix.rb +1 -1
  140. data/lib/chef/provider/service/debian.rb +3 -5
  141. data/lib/chef/provider/service/freebsd.rb +1 -1
  142. data/lib/chef/provider/service/gentoo.rb +3 -3
  143. data/lib/chef/provider/service/init.rb +3 -3
  144. data/lib/chef/provider/service/insserv.rb +2 -4
  145. data/lib/chef/provider/service/invokercd.rb +2 -4
  146. data/lib/chef/provider/service/macosx.rb +5 -1
  147. data/lib/chef/provider/service/openbsd.rb +2 -1
  148. data/lib/chef/provider/service/redhat.rb +52 -16
  149. data/lib/chef/provider/service/simple.rb +2 -2
  150. data/lib/chef/provider/service/systemd.rb +3 -5
  151. data/lib/chef/provider/service/upstart.rb +4 -6
  152. data/lib/chef/provider/subversion.rb +13 -7
  153. data/lib/chef/provider/template/content.rb +16 -6
  154. data/lib/chef/provider/user/solaris.rb +32 -4
  155. data/lib/chef/provider/windows_script.rb +3 -5
  156. data/lib/chef/provider_resolver.rb +2 -2
  157. data/lib/chef/recipe.rb +1 -8
  158. data/lib/chef/resource.rb +563 -90
  159. data/lib/chef/resource/action_class.rb +83 -0
  160. data/lib/chef/resource/chef_gem.rb +3 -3
  161. data/lib/chef/resource/deploy.rb +8 -2
  162. data/lib/chef/resource/dsc_script.rb +2 -0
  163. data/lib/chef/resource/file/verification.rb +7 -1
  164. data/lib/chef/resource/lwrp_base.rb +1 -7
  165. data/lib/chef/resource/registry_key.rb +1 -1
  166. data/lib/chef/resource/service.rb +10 -2
  167. data/lib/chef/resource/subversion.rb +5 -0
  168. data/lib/chef/resource/windows_script.rb +6 -2
  169. data/lib/chef/resource/yum_package.rb +10 -1
  170. data/lib/chef/resource_resolver.rb +3 -3
  171. data/lib/chef/run_context.rb +402 -83
  172. data/lib/chef/run_list/versioned_recipe_list.rb +15 -0
  173. data/lib/chef/run_lock.rb +30 -21
  174. data/lib/chef/util/powershell/ps_credential.rb +4 -0
  175. data/lib/chef/util/windows.rb +0 -32
  176. data/lib/chef/util/windows/net_group.rb +85 -106
  177. data/lib/chef/util/windows/net_use.rb +35 -71
  178. data/lib/chef/util/windows/net_user.rb +0 -1
  179. data/lib/chef/util/windows/volume.rb +19 -19
  180. data/lib/chef/version.rb +3 -3
  181. data/lib/chef/win32/api.rb +1 -0
  182. data/lib/chef/win32/api/file.rb +20 -0
  183. data/lib/chef/win32/api/net.rb +163 -43
  184. data/lib/chef/win32/api/registry.rb +51 -0
  185. data/lib/chef/win32/api/system.rb +23 -0
  186. data/lib/chef/win32/api/unicode.rb +0 -43
  187. data/lib/chef/win32/crypto.rb +2 -1
  188. data/lib/chef/win32/file.rb +28 -3
  189. data/lib/chef/win32/mutex.rb +1 -2
  190. data/lib/chef/win32/net.rb +162 -8
  191. data/lib/chef/win32/process.rb +13 -0
  192. data/lib/chef/win32/registry.rb +35 -30
  193. data/lib/chef/win32/security.rb +1 -1
  194. data/lib/chef/win32/security/token.rb +1 -1
  195. data/lib/chef/win32/system.rb +62 -0
  196. data/lib/chef/win32/unicode.rb +7 -2
  197. data/lib/chef/win32/version.rb +0 -4
  198. data/lib/chef/workstation_config_loader.rb +3 -158
  199. data/spec/data/cookbooks/openldap/templates/default/helpers.erb +14 -0
  200. data/spec/data/cookbooks/openldap/templates/default/nested_openldap_partials.erb +1 -0
  201. data/spec/data/cookbooks/openldap/templates/default/nested_partial.erb +1 -0
  202. data/spec/data/dsc_lcm.pfx +0 -0
  203. data/spec/data/run_context/cookbooks/include/recipes/default.rb +24 -0
  204. data/spec/data/run_context/cookbooks/include/recipes/includee.rb +3 -0
  205. data/spec/functional/dsl/reboot_pending_spec.rb +33 -43
  206. data/spec/functional/knife/cookbook_delete_spec.rb +17 -7
  207. data/spec/functional/knife/ssh_spec.rb +16 -0
  208. data/spec/functional/rebooter_spec.rb +1 -1
  209. data/spec/functional/resource/deploy_revision_spec.rb +1 -1
  210. data/spec/functional/resource/dsc_resource_spec.rb +2 -0
  211. data/spec/functional/resource/dsc_script_spec.rb +91 -2
  212. data/spec/functional/resource/group_spec.rb +67 -44
  213. data/spec/functional/resource/{powershell_spec.rb → powershell_script_spec.rb} +107 -18
  214. data/spec/functional/resource/windows_service_spec.rb +1 -1
  215. data/spec/functional/run_lock_spec.rb +368 -189
  216. data/spec/functional/win32/{registry_helper_spec.rb → registry_spec.rb} +16 -23
  217. data/spec/functional/win32/service_manager_spec.rb +2 -2
  218. data/spec/integration/client/client_spec.rb +51 -0
  219. data/spec/integration/knife/chef_repo_path_spec.rb +13 -11
  220. data/spec/integration/knife/download_spec.rb +4 -0
  221. data/spec/integration/knife/list_spec.rb +8 -0
  222. data/spec/integration/knife/upload_spec.rb +1 -1
  223. data/spec/integration/recipes/recipe_dsl_spec.rb +1 -16
  224. data/spec/integration/recipes/remote_directory.rb +74 -0
  225. data/spec/integration/recipes/resource_action_spec.rb +363 -0
  226. data/spec/integration/recipes/resource_converge_if_changed_spec.rb +423 -0
  227. data/spec/integration/recipes/resource_load_spec.rb +206 -0
  228. data/spec/spec_helper.rb +9 -0
  229. data/spec/support/platform_helpers.rb +13 -0
  230. data/spec/support/shared/context/win32.rb +34 -0
  231. data/spec/support/shared/functional/win32_service.rb +2 -1
  232. data/spec/support/shared/functional/windows_script.rb +63 -26
  233. data/spec/support/shared/unit/mock_shellout.rb +46 -0
  234. data/spec/support/shared/unit/provider/file.rb +10 -4
  235. data/spec/unit/application/client_spec.rb +16 -3
  236. data/spec/unit/application/knife_spec.rb +2 -2
  237. data/spec/unit/application/solo_spec.rb +4 -3
  238. data/spec/unit/chef_class_spec.rb +23 -4
  239. data/spec/unit/chef_fs/path_util_spec.rb +108 -0
  240. data/spec/unit/client_spec.rb +6 -1
  241. data/spec/unit/config_spec.rb +31 -0
  242. data/spec/unit/cookbook/metadata_spec.rb +23 -3
  243. data/spec/unit/cookbook/syntax_check_spec.rb +3 -0
  244. data/spec/unit/deprecation_spec.rb +3 -6
  245. data/spec/unit/dsl/reboot_pending_spec.rb +12 -6
  246. data/spec/unit/event_dispatch/dispatcher_spec.rb +65 -3
  247. data/spec/unit/event_dispatch/dsl_spec.rb +83 -0
  248. data/spec/unit/formatters/doc_spec.rb +32 -0
  249. data/spec/unit/formatters/error_inspectors/compile_error_inspector_spec.rb +26 -0
  250. data/spec/unit/json_compat_spec.rb +4 -3
  251. data/spec/unit/knife/bootstrap/client_builder_spec.rb +27 -0
  252. data/spec/unit/knife/bootstrap_spec.rb +55 -3
  253. data/spec/unit/knife/cookbook_site_share_spec.rb +3 -3
  254. data/spec/unit/knife/core/bootstrap_context_spec.rb +21 -4
  255. data/spec/unit/knife/core/custom_manifest_loader_spec.rb +41 -0
  256. data/spec/unit/knife/core/gem_glob_loader_spec.rb +210 -0
  257. data/spec/unit/knife/core/hashed_command_loader_spec.rb +93 -0
  258. data/spec/unit/knife/core/subcommand_loader_spec.rb +16 -192
  259. data/spec/unit/knife/node_run_list_remove_spec.rb +17 -0
  260. data/spec/unit/knife/ssl_check_spec.rb +4 -0
  261. data/spec/unit/mixin/enforce_ownership_and_permissions_spec.rb +10 -10
  262. data/spec/unit/mixin/params_validate_spec.rb +4 -2
  263. data/spec/unit/mixin/template_spec.rb +5 -1
  264. data/spec/unit/mixin/windows_architecture_helper_spec.rb +13 -8
  265. data/spec/unit/node_spec.rb +220 -0
  266. data/spec/unit/platform/query_helpers_spec.rb +146 -3
  267. data/spec/unit/policy_builder/dynamic_spec.rb +275 -0
  268. data/spec/unit/policy_builder/expand_node_object_spec.rb +37 -38
  269. data/spec/unit/policy_builder/policyfile_spec.rb +260 -46
  270. data/spec/unit/property/state_spec.rb +506 -0
  271. data/spec/unit/property/validation_spec.rb +663 -0
  272. data/spec/unit/property_spec.rb +1094 -0
  273. data/spec/unit/provider/deploy_spec.rb +5 -5
  274. data/spec/unit/provider/directory_spec.rb +35 -0
  275. data/spec/unit/provider/dsc_resource_spec.rb +3 -10
  276. data/spec/unit/provider/ifconfig_spec.rb +22 -2
  277. data/spec/unit/provider/mount/aix_spec.rb +2 -1
  278. data/spec/unit/provider/mount/mount_spec.rb +6 -0
  279. data/spec/unit/provider/mount/windows_spec.rb +14 -0
  280. data/spec/unit/provider/mount_spec.rb +12 -1
  281. data/spec/unit/provider/package/dpkg_spec.rb +8 -1
  282. data/spec/unit/provider/package/rpm_spec.rb +18 -1
  283. data/spec/unit/provider/package/rubygems_spec.rb +18 -0
  284. data/spec/unit/provider/package/yum_spec.rb +97 -24
  285. data/spec/unit/provider/powershell_script_spec.rb +106 -0
  286. data/spec/unit/provider/registry_key_spec.rb +12 -0
  287. data/spec/unit/provider/remote_directory_spec.rb +1 -2
  288. data/spec/unit/provider/service/aix_service_spec.rb +3 -3
  289. data/spec/unit/provider/service/gentoo_service_spec.rb +4 -4
  290. data/spec/unit/provider/service/macosx_spec.rb +4 -4
  291. data/spec/unit/provider/service/openbsd_service_spec.rb +10 -8
  292. data/spec/unit/provider/service/redhat_spec.rb +88 -8
  293. data/spec/unit/provider/service/upstart_service_spec.rb +11 -7
  294. data/spec/unit/provider/service/windows_spec.rb +211 -200
  295. data/spec/unit/provider/subversion_spec.rb +50 -31
  296. data/spec/unit/provider/template/content_spec.rb +93 -2
  297. data/spec/unit/provider/user/solaris_spec.rb +66 -9
  298. data/spec/unit/provider_resolver_spec.rb +707 -650
  299. data/spec/unit/provider_spec.rb +1 -3
  300. data/spec/unit/recipe_spec.rb +0 -4
  301. data/spec/unit/resource/deploy_spec.rb +7 -1
  302. data/spec/unit/resource/dsc_script_spec.rb +4 -0
  303. data/spec/unit/resource/file/verification_spec.rb +33 -5
  304. data/spec/unit/resource/{powershell_spec.rb → powershell_script_spec.rb} +17 -13
  305. data/spec/unit/resource/service_spec.rb +4 -4
  306. data/spec/unit/resource/subversion_spec.rb +4 -0
  307. data/spec/unit/resource/yum_package_spec.rb +10 -1
  308. data/spec/unit/resource_spec.rb +2 -2
  309. data/spec/unit/run_context/child_run_context_spec.rb +133 -0
  310. data/spec/unit/run_context_spec.rb +7 -0
  311. data/spec/unit/run_list/versioned_recipe_list_spec.rb +5 -0
  312. data/spec/unit/win32/registry_spec.rb +394 -0
  313. data/tasks/external_tests.rb +47 -23
  314. data/tasks/maintainers.rb +155 -14
  315. metadata +64 -53
  316. data/lib/chef/knife/bootstrap/templates/archlinux-gems.erb +0 -76
  317. data/lib/chef/knife/bootstrap/templates/chef-aix.erb +0 -72
  318. data/spec/unit/provider/powershell_spec.rb +0 -80
  319. data/spec/unit/registry_helper_spec.rb +0 -376
  320. data/spec/unit/workstation_config_loader_spec.rb +0 -283
@@ -21,369 +21,380 @@ require 'spec_helper'
21
21
  require 'mixlib/shellout'
22
22
 
23
23
  describe Chef::Provider::Service::Windows, "load_current_resource" do
24
- before(:each) do
25
- @node = Chef::Node.new
26
- @events = Chef::EventDispatch::Dispatcher.new
27
- @run_context = Chef::RunContext.new(@node, {}, @events)
28
- @new_resource = Chef::Resource::WindowsService.new("chef")
29
- @provider = Chef::Provider::Service::Windows.new(@new_resource, @run_context)
30
- @provider.current_resource = Chef::Resource::WindowsService.new("current-chef")
31
- Object.send(:remove_const, 'Win32') if defined?(Win32)
32
- Win32 = Module.new
24
+ include_context "Win32"
25
+
26
+ let(:new_resource) { Chef::Resource::WindowsService.new("chef") }
27
+ let(:provider) do
28
+ prvdr = Chef::Provider::Service::Windows.new(new_resource,
29
+ Chef::RunContext.new(Chef::Node.new, {}, Chef::EventDispatch::Dispatcher.new))
30
+ prvdr.current_resource = Chef::Resource::WindowsService.new("current-chef")
31
+ prvdr
32
+ end
33
+
34
+ before(:all) do
33
35
  Win32::Service = Class.new
36
+ end
37
+
38
+ before(:each) do
34
39
  Win32::Service::AUTO_START = 0x00000002
35
40
  Win32::Service::DEMAND_START = 0x00000003
36
41
  Win32::Service::DISABLED = 0x00000004
37
- allow(Win32::Service).to receive(:status).with(@new_resource.service_name).and_return(
42
+
43
+ allow(Win32::Service).to receive(:status).with(new_resource.service_name).and_return(
38
44
  double("StatusStruct", :current_state => "running"))
39
- allow(Win32::Service).to receive(:config_info).with(@new_resource.service_name).and_return(
45
+ allow(Win32::Service).to receive(:config_info).with(new_resource.service_name).and_return(
40
46
  double("ConfigStruct", :start_type => "auto start"))
41
47
  allow(Win32::Service).to receive(:exists?).and_return(true)
42
48
  allow(Win32::Service).to receive(:configure).and_return(Win32::Service)
43
49
  end
44
50
 
45
- it "should set the current resources service name to the new resources service name" do
46
- @provider.load_current_resource
47
- expect(@provider.current_resource.service_name).to eq('chef')
51
+ after(:each) do
52
+ Win32::Service.send(:remove_const, 'AUTO_START') if defined?(Win32::Service::AUTO_START)
53
+ Win32::Service.send(:remove_const, 'DEMAND_START') if defined?(Win32::Service::DEMAND_START)
54
+ Win32::Service.send(:remove_const, 'DISABLED') if defined?(Win32::Service::DISABLED)
48
55
  end
49
56
 
50
- it "should return the current resource" do
51
- expect(@provider.load_current_resource).to equal(@provider.current_resource)
57
+ it "sets the current resources service name to the new resources service name" do
58
+ provider.load_current_resource
59
+ expect(provider.current_resource.service_name).to eq('chef')
52
60
  end
53
61
 
54
- it "should set the current resources status" do
55
- @provider.load_current_resource
56
- expect(@provider.current_resource.running).to be_truthy
62
+ it "returns the current resource" do
63
+ expect(provider.load_current_resource).to equal(provider.current_resource)
57
64
  end
58
65
 
59
- it "should set the current resources start type" do
60
- @provider.load_current_resource
61
- expect(@provider.current_resource.enabled).to be_truthy
66
+ it "sets the current resources status" do
67
+ provider.load_current_resource
68
+ expect(provider.current_resource.running).to be_truthy
69
+ end
70
+
71
+ it "sets the current resources start type" do
72
+ provider.load_current_resource
73
+ expect(provider.current_resource.enabled).to be_truthy
62
74
  end
63
75
 
64
76
  it "does not set the current resources start type if it is neither AUTO START or DISABLED" do
65
- allow(Win32::Service).to receive(:config_info).with(@new_resource.service_name).and_return(
77
+ allow(Win32::Service).to receive(:config_info).with(new_resource.service_name).and_return(
66
78
  double("ConfigStruct", :start_type => "manual"))
67
- @provider.load_current_resource
68
- expect(@provider.current_resource.enabled).to be_nil
79
+ provider.load_current_resource
80
+ expect(provider.current_resource.enabled).to be_nil
69
81
  end
70
82
 
71
83
  describe Chef::Provider::Service::Windows, "start_service" do
72
84
  before(:each) do
73
- allow(Win32::Service).to receive(:status).with(@new_resource.service_name).and_return(
85
+ allow(Win32::Service).to receive(:status).with(new_resource.service_name).and_return(
74
86
  double("StatusStruct", :current_state => "stopped"),
75
87
  double("StatusStruct", :current_state => "running"))
76
88
  end
77
89
 
78
- it "should call the start command if one is specified" do
79
- @new_resource.start_command "sc start chef"
80
- expect(@provider).to receive(:shell_out!).with("#{@new_resource.start_command}").and_return("Starting custom service")
81
- @provider.start_service
82
- expect(@new_resource.updated_by_last_action?).to be_truthy
90
+ it "calls the start command if one is specified" do
91
+ new_resource.start_command "sc start chef"
92
+ expect(provider).to receive(:shell_out!).with("#{new_resource.start_command}").and_return("Starting custom service")
93
+ provider.start_service
94
+ expect(new_resource.updated_by_last_action?).to be_truthy
83
95
  end
84
96
 
85
- it "should use the built-in command if no start command is specified" do
86
- expect(Win32::Service).to receive(:start).with(@new_resource.service_name)
87
- @provider.start_service
88
- expect(@new_resource.updated_by_last_action?).to be_truthy
97
+ it "uses the built-in command if no start command is specified" do
98
+ expect(Win32::Service).to receive(:start).with(new_resource.service_name)
99
+ provider.start_service
100
+ expect(new_resource.updated_by_last_action?).to be_truthy
89
101
  end
90
102
 
91
- it "should do nothing if the service does not exist" do
92
- allow(Win32::Service).to receive(:exists?).with(@new_resource.service_name).and_return(false)
93
- expect(Win32::Service).not_to receive(:start).with(@new_resource.service_name)
94
- @provider.start_service
95
- expect(@new_resource.updated_by_last_action?).to be_falsey
103
+ it "does nothing if the service does not exist" do
104
+ allow(Win32::Service).to receive(:exists?).with(new_resource.service_name).and_return(false)
105
+ expect(Win32::Service).not_to receive(:start).with(new_resource.service_name)
106
+ provider.start_service
107
+ expect(new_resource.updated_by_last_action?).to be_falsey
96
108
  end
97
109
 
98
- it "should do nothing if the service is running" do
99
- allow(Win32::Service).to receive(:status).with(@new_resource.service_name).and_return(
110
+ it "does nothing if the service is running" do
111
+ allow(Win32::Service).to receive(:status).with(new_resource.service_name).and_return(
100
112
  double("StatusStruct", :current_state => "running"))
101
- @provider.load_current_resource
102
- expect(Win32::Service).not_to receive(:start).with(@new_resource.service_name)
103
- @provider.start_service
104
- expect(@new_resource.updated_by_last_action?).to be_falsey
113
+ provider.load_current_resource
114
+ expect(Win32::Service).not_to receive(:start).with(new_resource.service_name)
115
+ provider.start_service
116
+ expect(new_resource.updated_by_last_action?).to be_falsey
105
117
  end
106
118
 
107
- it "should raise an error if the service is paused" do
108
- allow(Win32::Service).to receive(:status).with(@new_resource.service_name).and_return(
119
+ it "raises an error if the service is paused" do
120
+ allow(Win32::Service).to receive(:status).with(new_resource.service_name).and_return(
109
121
  double("StatusStruct", :current_state => "paused"))
110
- @provider.load_current_resource
111
- expect(Win32::Service).not_to receive(:start).with(@new_resource.service_name)
112
- expect { @provider.start_service }.to raise_error( Chef::Exceptions::Service )
113
- expect(@new_resource.updated_by_last_action?).to be_falsey
122
+ provider.load_current_resource
123
+ expect(Win32::Service).not_to receive(:start).with(new_resource.service_name)
124
+ expect { provider.start_service }.to raise_error( Chef::Exceptions::Service )
125
+ expect(new_resource.updated_by_last_action?).to be_falsey
114
126
  end
115
127
 
116
- it "should wait and continue if the service is in start_pending" do
117
- allow(Win32::Service).to receive(:status).with(@new_resource.service_name).and_return(
128
+ it "waits and continues if the service is in start_pending" do
129
+ allow(Win32::Service).to receive(:status).with(new_resource.service_name).and_return(
118
130
  double("StatusStruct", :current_state => "start pending"),
119
131
  double("StatusStruct", :current_state => "start pending"),
120
132
  double("StatusStruct", :current_state => "running"))
121
- @provider.load_current_resource
122
- expect(Win32::Service).not_to receive(:start).with(@new_resource.service_name)
123
- @provider.start_service
124
- expect(@new_resource.updated_by_last_action?).to be_falsey
133
+ provider.load_current_resource
134
+ expect(Win32::Service).not_to receive(:start).with(new_resource.service_name)
135
+ provider.start_service
136
+ expect(new_resource.updated_by_last_action?).to be_falsey
125
137
  end
126
138
 
127
- it "should fail if the service is in stop_pending" do
128
- allow(Win32::Service).to receive(:status).with(@new_resource.service_name).and_return(
139
+ it "fails if the service is in stop_pending" do
140
+ allow(Win32::Service).to receive(:status).with(new_resource.service_name).and_return(
129
141
  double("StatusStruct", :current_state => "stop pending"))
130
- @provider.load_current_resource
131
- expect(Win32::Service).not_to receive(:start).with(@new_resource.service_name)
132
- expect { @provider.start_service }.to raise_error( Chef::Exceptions::Service )
133
- expect(@new_resource.updated_by_last_action?).to be_falsey
142
+ provider.load_current_resource
143
+ expect(Win32::Service).not_to receive(:start).with(new_resource.service_name)
144
+ expect { provider.start_service }.to raise_error( Chef::Exceptions::Service )
145
+ expect(new_resource.updated_by_last_action?).to be_falsey
134
146
  end
135
147
 
136
148
  describe "running as a different account" do
137
- let(:old_run_as_user) { @new_resource.run_as_user }
138
- let(:old_run_as_password) { @new_resource.run_as_password }
149
+ let(:old_run_as_user) { new_resource.run_as_user }
150
+ let(:old_run_as_password) { new_resource.run_as_password }
139
151
 
140
152
  before {
141
- @new_resource.run_as_user(".\\wallace")
142
- @new_resource.run_as_password("Wensleydale")
153
+ new_resource.run_as_user(".\\wallace")
154
+ new_resource.run_as_password("Wensleydale")
143
155
  }
144
156
 
145
157
  after {
146
- @new_resource.run_as_user(old_run_as_user)
147
- @new_resource.run_as_password(old_run_as_password)
158
+ new_resource.run_as_user(old_run_as_user)
159
+ new_resource.run_as_password(old_run_as_password)
148
160
  }
149
161
 
150
- it "should call #grant_service_logon if the :run_as_user and :run_as_password attributes are present" do
162
+ it "calls #grant_service_logon if the :run_as_user and :run_as_password attributes are present" do
151
163
  expect(Win32::Service).to receive(:start)
152
- expect(@provider).to receive(:grant_service_logon).and_return(true)
153
- @provider.start_service
164
+ expect(provider).to receive(:grant_service_logon).and_return(true)
165
+ provider.start_service
154
166
  end
155
167
  end
156
168
  end
157
169
 
158
-
159
170
  describe Chef::Provider::Service::Windows, "stop_service" do
160
171
 
161
172
  before(:each) do
162
- allow(Win32::Service).to receive(:status).with(@new_resource.service_name).and_return(
173
+ allow(Win32::Service).to receive(:status).with(new_resource.service_name).and_return(
163
174
  double("StatusStruct", :current_state => "running"),
164
175
  double("StatusStruct", :current_state => "stopped"))
165
176
  end
166
177
 
167
- it "should call the stop command if one is specified" do
168
- @new_resource.stop_command "sc stop chef"
169
- expect(@provider).to receive(:shell_out!).with("#{@new_resource.stop_command}").and_return("Stopping custom service")
170
- @provider.stop_service
171
- expect(@new_resource.updated_by_last_action?).to be_truthy
178
+ it "calls the stop command if one is specified" do
179
+ new_resource.stop_command "sc stop chef"
180
+ expect(provider).to receive(:shell_out!).with("#{new_resource.stop_command}").and_return("Stopping custom service")
181
+ provider.stop_service
182
+ expect(new_resource.updated_by_last_action?).to be_truthy
172
183
  end
173
184
 
174
- it "should use the built-in command if no stop command is specified" do
175
- expect(Win32::Service).to receive(:stop).with(@new_resource.service_name)
176
- @provider.stop_service
177
- expect(@new_resource.updated_by_last_action?).to be_truthy
185
+ it "uses the built-in command if no stop command is specified" do
186
+ expect(Win32::Service).to receive(:stop).with(new_resource.service_name)
187
+ provider.stop_service
188
+ expect(new_resource.updated_by_last_action?).to be_truthy
178
189
  end
179
190
 
180
- it "should do nothing if the service does not exist" do
181
- allow(Win32::Service).to receive(:exists?).with(@new_resource.service_name).and_return(false)
182
- expect(Win32::Service).not_to receive(:stop).with(@new_resource.service_name)
183
- @provider.stop_service
184
- expect(@new_resource.updated_by_last_action?).to be_falsey
191
+ it "does nothing if the service does not exist" do
192
+ allow(Win32::Service).to receive(:exists?).with(new_resource.service_name).and_return(false)
193
+ expect(Win32::Service).not_to receive(:stop).with(new_resource.service_name)
194
+ provider.stop_service
195
+ expect(new_resource.updated_by_last_action?).to be_falsey
185
196
  end
186
197
 
187
- it "should do nothing if the service is stopped" do
188
- allow(Win32::Service).to receive(:status).with(@new_resource.service_name).and_return(
198
+ it "does nothing if the service is stopped" do
199
+ allow(Win32::Service).to receive(:status).with(new_resource.service_name).and_return(
189
200
  double("StatusStruct", :current_state => "stopped"))
190
- @provider.load_current_resource
191
- expect(Win32::Service).not_to receive(:stop).with(@new_resource.service_name)
192
- @provider.stop_service
193
- expect(@new_resource.updated_by_last_action?).to be_falsey
201
+ provider.load_current_resource
202
+ expect(Win32::Service).not_to receive(:stop).with(new_resource.service_name)
203
+ provider.stop_service
204
+ expect(new_resource.updated_by_last_action?).to be_falsey
194
205
  end
195
206
 
196
- it "should raise an error if the service is paused" do
197
- allow(Win32::Service).to receive(:status).with(@new_resource.service_name).and_return(
207
+ it "raises an error if the service is paused" do
208
+ allow(Win32::Service).to receive(:status).with(new_resource.service_name).and_return(
198
209
  double("StatusStruct", :current_state => "paused"))
199
- @provider.load_current_resource
200
- expect(Win32::Service).not_to receive(:start).with(@new_resource.service_name)
201
- expect { @provider.stop_service }.to raise_error( Chef::Exceptions::Service )
202
- expect(@new_resource.updated_by_last_action?).to be_falsey
210
+ provider.load_current_resource
211
+ expect(Win32::Service).not_to receive(:start).with(new_resource.service_name)
212
+ expect { provider.stop_service }.to raise_error( Chef::Exceptions::Service )
213
+ expect(new_resource.updated_by_last_action?).to be_falsey
203
214
  end
204
215
 
205
- it "should wait and continue if the service is in stop_pending" do
206
- allow(Win32::Service).to receive(:status).with(@new_resource.service_name).and_return(
216
+ it "waits and continue if the service is in stop_pending" do
217
+ allow(Win32::Service).to receive(:status).with(new_resource.service_name).and_return(
207
218
  double("StatusStruct", :current_state => "stop pending"),
208
219
  double("StatusStruct", :current_state => "stop pending"),
209
220
  double("StatusStruct", :current_state => "stopped"))
210
- @provider.load_current_resource
211
- expect(Win32::Service).not_to receive(:stop).with(@new_resource.service_name)
212
- @provider.stop_service
213
- expect(@new_resource.updated_by_last_action?).to be_falsey
221
+ provider.load_current_resource
222
+ expect(Win32::Service).not_to receive(:stop).with(new_resource.service_name)
223
+ provider.stop_service
224
+ expect(new_resource.updated_by_last_action?).to be_falsey
214
225
  end
215
226
 
216
- it "should fail if the service is in start_pending" do
217
- allow(Win32::Service).to receive(:status).with(@new_resource.service_name).and_return(
227
+ it "fails if the service is in start_pending" do
228
+ allow(Win32::Service).to receive(:status).with(new_resource.service_name).and_return(
218
229
  double("StatusStruct", :current_state => "start pending"))
219
- @provider.load_current_resource
220
- expect(Win32::Service).not_to receive(:stop).with(@new_resource.service_name)
221
- expect { @provider.stop_service }.to raise_error( Chef::Exceptions::Service )
222
- expect(@new_resource.updated_by_last_action?).to be_falsey
230
+ provider.load_current_resource
231
+ expect(Win32::Service).not_to receive(:stop).with(new_resource.service_name)
232
+ expect { provider.stop_service }.to raise_error( Chef::Exceptions::Service )
233
+ expect(new_resource.updated_by_last_action?).to be_falsey
223
234
  end
224
235
 
225
- it "should pass custom timeout to the stop command if provided" do
226
- allow(Win32::Service).to receive(:status).with(@new_resource.service_name).and_return(
236
+ it "passes custom timeout to the stop command if provided" do
237
+ allow(Win32::Service).to receive(:status).with(new_resource.service_name).and_return(
227
238
  double("StatusStruct", :current_state => "running"))
228
- @new_resource.timeout 1
229
- expect(Win32::Service).to receive(:stop).with(@new_resource.service_name)
239
+ new_resource.timeout 1
240
+ expect(Win32::Service).to receive(:stop).with(new_resource.service_name)
230
241
  Timeout.timeout(2) do
231
- expect { @provider.stop_service }.to raise_error(Timeout::Error)
242
+ expect { provider.stop_service }.to raise_error(Timeout::Error)
232
243
  end
233
- expect(@new_resource.updated_by_last_action?).to be_falsey
244
+ expect(new_resource.updated_by_last_action?).to be_falsey
234
245
  end
235
246
 
236
247
  end
237
248
 
238
249
  describe Chef::Provider::Service::Windows, "restart_service" do
239
250
 
240
- it "should call the restart command if one is specified" do
241
- @new_resource.restart_command "sc restart"
242
- expect(@provider).to receive(:shell_out!).with("#{@new_resource.restart_command}")
243
- @provider.restart_service
244
- expect(@new_resource.updated_by_last_action?).to be_truthy
251
+ it "calls the restart command if one is specified" do
252
+ new_resource.restart_command "sc restart"
253
+ expect(provider).to receive(:shell_out!).with("#{new_resource.restart_command}")
254
+ provider.restart_service
255
+ expect(new_resource.updated_by_last_action?).to be_truthy
245
256
  end
246
257
 
247
- it "should stop then start the service if it is running" do
248
- allow(Win32::Service).to receive(:status).with(@new_resource.service_name).and_return(
258
+ it "stops then starts the service if it is running" do
259
+ allow(Win32::Service).to receive(:status).with(new_resource.service_name).and_return(
249
260
  double("StatusStruct", :current_state => "running"),
250
261
  double("StatusStruct", :current_state => "stopped"),
251
262
  double("StatusStruct", :current_state => "stopped"),
252
263
  double("StatusStruct", :current_state => "running"))
253
- expect(Win32::Service).to receive(:stop).with(@new_resource.service_name)
254
- expect(Win32::Service).to receive(:start).with(@new_resource.service_name)
255
- @provider.restart_service
256
- expect(@new_resource.updated_by_last_action?).to be_truthy
264
+ expect(Win32::Service).to receive(:stop).with(new_resource.service_name)
265
+ expect(Win32::Service).to receive(:start).with(new_resource.service_name)
266
+ provider.restart_service
267
+ expect(new_resource.updated_by_last_action?).to be_truthy
257
268
  end
258
269
 
259
- it "should just start the service if it is stopped" do
260
- allow(Win32::Service).to receive(:status).with(@new_resource.service_name).and_return(
270
+ it "just starts the service if it is stopped" do
271
+ allow(Win32::Service).to receive(:status).with(new_resource.service_name).and_return(
261
272
  double("StatusStruct", :current_state => "stopped"),
262
273
  double("StatusStruct", :current_state => "stopped"),
263
274
  double("StatusStruct", :current_state => "running"))
264
- expect(Win32::Service).to receive(:start).with(@new_resource.service_name)
265
- @provider.restart_service
266
- expect(@new_resource.updated_by_last_action?).to be_truthy
275
+ expect(Win32::Service).to receive(:start).with(new_resource.service_name)
276
+ provider.restart_service
277
+ expect(new_resource.updated_by_last_action?).to be_truthy
267
278
  end
268
279
 
269
- it "should do nothing if the service does not exist" do
270
- allow(Win32::Service).to receive(:exists?).with(@new_resource.service_name).and_return(false)
271
- expect(Win32::Service).not_to receive(:stop).with(@new_resource.service_name)
272
- expect(Win32::Service).not_to receive(:start).with(@new_resource.service_name)
273
- @provider.restart_service
274
- expect(@new_resource.updated_by_last_action?).to be_falsey
280
+ it "does nothing if the service does not exist" do
281
+ allow(Win32::Service).to receive(:exists?).with(new_resource.service_name).and_return(false)
282
+ expect(Win32::Service).not_to receive(:stop).with(new_resource.service_name)
283
+ expect(Win32::Service).not_to receive(:start).with(new_resource.service_name)
284
+ provider.restart_service
285
+ expect(new_resource.updated_by_last_action?).to be_falsey
275
286
  end
276
287
 
277
288
  end
278
289
 
279
290
  describe Chef::Provider::Service::Windows, "enable_service" do
280
291
  before(:each) do
281
- allow(Win32::Service).to receive(:config_info).with(@new_resource.service_name).and_return(
292
+ allow(Win32::Service).to receive(:config_info).with(new_resource.service_name).and_return(
282
293
  double("ConfigStruct", :start_type => "disabled"))
283
294
  end
284
295
 
285
- it "should enable service" do
286
- expect(Win32::Service).to receive(:configure).with(:service_name => @new_resource.service_name, :start_type => Win32::Service::AUTO_START)
287
- @provider.enable_service
288
- expect(@new_resource.updated_by_last_action?).to be_truthy
296
+ it "enables service" do
297
+ expect(Win32::Service).to receive(:configure).with(:service_name => new_resource.service_name, :start_type => Win32::Service::AUTO_START)
298
+ provider.enable_service
299
+ expect(new_resource.updated_by_last_action?).to be_truthy
289
300
  end
290
301
 
291
- it "should do nothing if the service does not exist" do
292
- allow(Win32::Service).to receive(:exists?).with(@new_resource.service_name).and_return(false)
302
+ it "does nothing if the service does not exist" do
303
+ allow(Win32::Service).to receive(:exists?).with(new_resource.service_name).and_return(false)
293
304
  expect(Win32::Service).not_to receive(:configure)
294
- @provider.enable_service
295
- expect(@new_resource.updated_by_last_action?).to be_falsey
305
+ provider.enable_service
306
+ expect(new_resource.updated_by_last_action?).to be_falsey
296
307
  end
297
308
  end
298
309
 
299
310
  describe Chef::Provider::Service::Windows, "action_enable" do
300
311
  it "does nothing if the service is enabled" do
301
- allow(Win32::Service).to receive(:config_info).with(@new_resource.service_name).and_return(
312
+ allow(Win32::Service).to receive(:config_info).with(new_resource.service_name).and_return(
302
313
  double("ConfigStruct", :start_type => "auto start"))
303
- expect(@provider).not_to receive(:enable_service)
304
- @provider.action_enable
314
+ expect(provider).not_to receive(:enable_service)
315
+ provider.action_enable
305
316
  end
306
317
 
307
318
  it "enables the service if it is not set to automatic start" do
308
- allow(Win32::Service).to receive(:config_info).with(@new_resource.service_name).and_return(
319
+ allow(Win32::Service).to receive(:config_info).with(new_resource.service_name).and_return(
309
320
  double("ConfigStruct", :start_type => "disabled"))
310
- expect(@provider).to receive(:enable_service)
311
- @provider.action_enable
321
+ expect(provider).to receive(:enable_service)
322
+ provider.action_enable
312
323
  end
313
324
  end
314
325
 
315
326
  describe Chef::Provider::Service::Windows, "action_disable" do
316
327
  it "does nothing if the service is disabled" do
317
- allow(Win32::Service).to receive(:config_info).with(@new_resource.service_name).and_return(
328
+ allow(Win32::Service).to receive(:config_info).with(new_resource.service_name).and_return(
318
329
  double("ConfigStruct", :start_type => "disabled"))
319
- expect(@provider).not_to receive(:disable_service)
320
- @provider.action_disable
330
+ expect(provider).not_to receive(:disable_service)
331
+ provider.action_disable
321
332
  end
322
333
 
323
334
  it "disables the service if it is not set to disabled" do
324
- allow(Win32::Service).to receive(:config_info).with(@new_resource.service_name).and_return(
335
+ allow(Win32::Service).to receive(:config_info).with(new_resource.service_name).and_return(
325
336
  double("ConfigStruct", :start_type => "auto start"))
326
- expect(@provider).to receive(:disable_service)
327
- @provider.action_disable
337
+ expect(provider).to receive(:disable_service)
338
+ provider.action_disable
328
339
  end
329
340
  end
330
341
 
331
342
  describe Chef::Provider::Service::Windows, "disable_service" do
332
343
  before(:each) do
333
- allow(Win32::Service).to receive(:config_info).with(@new_resource.service_name).and_return(
344
+ allow(Win32::Service).to receive(:config_info).with(new_resource.service_name).and_return(
334
345
  double("ConfigStruct", :start_type => "auto start"))
335
346
  end
336
347
 
337
- it "should disable service" do
348
+ it "disables service" do
338
349
  expect(Win32::Service).to receive(:configure)
339
- @provider.disable_service
340
- expect(@new_resource.updated_by_last_action?).to be_truthy
350
+ provider.disable_service
351
+ expect(new_resource.updated_by_last_action?).to be_truthy
341
352
  end
342
353
 
343
- it "should do nothing if the service does not exist" do
344
- allow(Win32::Service).to receive(:exists?).with(@new_resource.service_name).and_return(false)
354
+ it "does nothing if the service does not exist" do
355
+ allow(Win32::Service).to receive(:exists?).with(new_resource.service_name).and_return(false)
345
356
  expect(Win32::Service).not_to receive(:configure)
346
- @provider.disable_service
347
- expect(@new_resource.updated_by_last_action?).to be_falsey
357
+ provider.disable_service
358
+ expect(new_resource.updated_by_last_action?).to be_falsey
348
359
  end
349
360
  end
350
361
 
351
362
  describe Chef::Provider::Service::Windows, "action_configure_startup" do
352
363
  { :automatic => "auto start", :manual => "demand start", :disabled => "disabled" }.each do |type,win32|
353
364
  it "sets the startup type to #{type} if it is something else" do
354
- @new_resource.startup_type(type)
355
- allow(@provider).to receive(:current_start_type).and_return("fire")
356
- expect(@provider).to receive(:set_startup_type).with(type)
357
- @provider.action_configure_startup
365
+ new_resource.startup_type(type)
366
+ allow(provider).to receive(:current_start_type).and_return("fire")
367
+ expect(provider).to receive(:set_startup_type).with(type)
368
+ provider.action_configure_startup
358
369
  end
359
370
 
360
371
  it "leaves the startup type as #{type} if it is already set" do
361
- @new_resource.startup_type(type)
362
- allow(@provider).to receive(:current_start_type).and_return(win32)
363
- expect(@provider).not_to receive(:set_startup_type).with(type)
364
- @provider.action_configure_startup
372
+ new_resource.startup_type(type)
373
+ allow(provider).to receive(:current_start_type).and_return(win32)
374
+ expect(provider).not_to receive(:set_startup_type).with(type)
375
+ provider.action_configure_startup
365
376
  end
366
377
  end
367
378
  end
368
379
 
369
380
  describe Chef::Provider::Service::Windows, "set_start_type" do
370
381
  it "when called with :automatic it calls Win32::Service#configure with Win32::Service::AUTO_START" do
371
- expect(Win32::Service).to receive(:configure).with(:service_name => @new_resource.service_name, :start_type => Win32::Service::AUTO_START)
372
- @provider.send(:set_startup_type, :automatic)
382
+ expect(Win32::Service).to receive(:configure).with(:service_name => new_resource.service_name, :start_type => Win32::Service::AUTO_START)
383
+ provider.send(:set_startup_type, :automatic)
373
384
  end
374
385
 
375
386
  it "when called with :manual it calls Win32::Service#configure with Win32::Service::DEMAND_START" do
376
- expect(Win32::Service).to receive(:configure).with(:service_name => @new_resource.service_name, :start_type => Win32::Service::DEMAND_START)
377
- @provider.send(:set_startup_type, :manual)
387
+ expect(Win32::Service).to receive(:configure).with(:service_name => new_resource.service_name, :start_type => Win32::Service::DEMAND_START)
388
+ provider.send(:set_startup_type, :manual)
378
389
  end
379
390
 
380
391
  it "when called with :disabled it calls Win32::Service#configure with Win32::Service::DISABLED" do
381
- expect(Win32::Service).to receive(:configure).with(:service_name => @new_resource.service_name, :start_type => Win32::Service::DISABLED)
382
- @provider.send(:set_startup_type, :disabled)
392
+ expect(Win32::Service).to receive(:configure).with(:service_name => new_resource.service_name, :start_type => Win32::Service::DISABLED)
393
+ provider.send(:set_startup_type, :disabled)
383
394
  end
384
395
 
385
396
  it "raises an exception when given an unknown start type" do
386
- expect { @provider.send(:set_startup_type, :fire_truck) }.to raise_error(Chef::Exceptions::ConfigurationError)
397
+ expect { provider.send(:set_startup_type, :fire_truck) }.to raise_error(Chef::Exceptions::ConfigurationError)
387
398
  end
388
399
  end
389
400
 
@@ -409,9 +420,9 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do
409
420
  let(:success_string) { "The task has completed successfully.\r\nSee logfile etc." }
410
421
  let(:failure_string) { "Look on my works, ye Mighty, and despair!" }
411
422
  let(:command) {
412
- dbfile = @provider.grant_dbfile_name(username)
413
- policyfile = @provider.grant_policyfile_name(username)
414
- logfile = @provider.grant_logfile_name(username)
423
+ dbfile = provider.grant_dbfile_name(username)
424
+ policyfile = provider.grant_policyfile_name(username)
425
+ logfile = provider.grant_logfile_name(username)
415
426
 
416
427
  %Q{secedit.exe /configure /db "#{dbfile}" /cfg "#{policyfile}" /areas USER_RIGHTS SECURITYPOLICY SERVICES /log "#{logfile}"}
417
428
  }
@@ -424,20 +435,20 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do
424
435
 
425
436
  after {
426
437
  # only needed for the second test.
427
- ::File.delete(@provider.grant_policyfile_name(username)) rescue nil
428
- ::File.delete(@provider.grant_logfile_name(username)) rescue nil
429
- ::File.delete(@provider.grant_dbfile_name(username)) rescue nil
438
+ ::File.delete(provider.grant_policyfile_name(username)) rescue nil
439
+ ::File.delete(provider.grant_logfile_name(username)) rescue nil
440
+ ::File.delete(provider.grant_dbfile_name(username)) rescue nil
430
441
  }
431
442
 
432
443
  it "calls Mixlib::Shellout with the correct command string" do
433
444
  expect_any_instance_of(Mixlib::ShellOut).to receive(:exitstatus).and_return(0)
434
- expect(@provider.grant_service_logon(username)).to equal true
445
+ expect(provider.grant_service_logon(username)).to equal true
435
446
  end
436
447
 
437
448
  it "raises an exception when the grant command fails" do
438
449
  expect_any_instance_of(Mixlib::ShellOut).to receive(:exitstatus).and_return(1)
439
450
  expect_any_instance_of(Mixlib::ShellOut).to receive(:stdout).and_return(failure_string)
440
- expect { @provider.grant_service_logon(username) }.to raise_error(Chef::Exceptions::Service)
451
+ expect { provider.grant_service_logon(username) }.to raise_error(Chef::Exceptions::Service)
441
452
  end
442
453
  end
443
454
 
@@ -445,17 +456,17 @@ describe Chef::Provider::Service::Windows, "load_current_resource" do
445
456
  include_context "testing private methods"
446
457
 
447
458
  it "correctly reformats usernames to create valid filenames" do
448
- expect(@provider.clean_username_for_path("\\\\problem username/oink.txt")).to eq("_problem_username_oink_txt")
449
- expect(@provider.clean_username_for_path("boring_username")).to eq("boring_username")
459
+ expect(provider.clean_username_for_path("\\\\problem username/oink.txt")).to eq("_problem_username_oink_txt")
460
+ expect(provider.clean_username_for_path("boring_username")).to eq("boring_username")
450
461
  end
451
462
 
452
463
  it "correctly reformats usernames for the policy file" do
453
- expect(@provider.canonicalize_username(".\\maryann")).to eq("maryann")
454
- expect(@provider.canonicalize_username("maryann")).to eq("maryann")
464
+ expect(provider.canonicalize_username(".\\maryann")).to eq("maryann")
465
+ expect(provider.canonicalize_username("maryann")).to eq("maryann")
455
466
 
456
- expect(@provider.canonicalize_username("\\\\maryann")).to eq("maryann")
457
- expect(@provider.canonicalize_username("mydomain\\\\maryann")).to eq("mydomain\\\\maryann")
458
- expect(@provider.canonicalize_username("\\\\mydomain\\\\maryann")).to eq("mydomain\\\\maryann")
467
+ expect(provider.canonicalize_username("\\\\maryann")).to eq("maryann")
468
+ expect(provider.canonicalize_username("mydomain\\\\maryann")).to eq("mydomain\\\\maryann")
469
+ expect(provider.canonicalize_username("\\\\mydomain\\\\maryann")).to eq("mydomain\\\\maryann")
459
470
  end
460
471
  end
461
472
  end