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
@@ -38,41 +38,67 @@ describe Chef::Provider::PowershellScript, "action_run" do
38
38
  }
39
39
 
40
40
  context 'when setting interpreter flags' do
41
- it "should set the -File flag as the last flag" do
42
- expect(provider.flags.split(' ').pop).to eq("-File")
41
+ context 'on nano' do
42
+ before(:each) do
43
+ allow(Chef::Platform).to receive(:windows_nano_server?).and_return(true)
44
+ allow(provider).to receive(:is_forced_32bit).and_return(false)
45
+ os_info_double = double("os_info")
46
+ allow(provider.run_context.node.kernel).to receive(:os_info).and_return(os_info_double)
47
+ allow(os_info_double).to receive(:system_directory).and_return("C:\\Windows\\system32")
48
+ end
49
+
50
+ it "sets the -Command flag as the last flag" do
51
+ flags = provider.command.split(' ').keep_if { |flag| flag =~ /^-/ }
52
+ expect(flags.pop).to eq("-Command")
53
+ end
43
54
  end
44
55
 
45
- let(:execution_policy_flag) do
46
- execution_policy_index = 0
47
- provider_flags = provider.flags.split(' ')
48
- execution_policy_specified = false
56
+ context 'not on nano' do
57
+ before(:each) do
58
+ allow(Chef::Platform).to receive(:windows_nano_server?).and_return(false)
59
+ allow(provider).to receive(:is_forced_32bit).and_return(false)
60
+ os_info_double = double("os_info")
61
+ allow(provider.run_context.node.kernel).to receive(:os_info).and_return(os_info_double)
62
+ allow(os_info_double).to receive(:system_directory).and_return("C:\\Windows\\system32")
63
+ end
49
64
 
50
- provider_flags.find do | value |
51
- execution_policy_index += 1
52
- execution_policy_specified = value.downcase == '-ExecutionPolicy'.downcase
65
+ it "sets the -File flag as the last flag" do
66
+ flags = provider.command.split(' ').keep_if { |flag| flag =~ /^-/ }
67
+ expect(flags.pop).to eq("-File")
53
68
  end
54
69
 
55
- execution_policy = execution_policy_specified ? provider_flags[execution_policy_index] : nil
56
- end
70
+ let(:execution_policy_flag) do
71
+ execution_policy_index = 0
72
+ provider_flags = provider.flags.split(' ')
73
+ execution_policy_specified = false
57
74
 
58
- context 'when running with an unspecified PowerShell version' do
59
- let(:powershell_version) { nil }
60
- it "should set the -ExecutionPolicy flag to 'Unrestricted' by default" do
61
- expect(execution_policy_flag.downcase).to eq('unrestricted'.downcase)
75
+ provider_flags.find do | value |
76
+ execution_policy_index += 1
77
+ execution_policy_specified = value.downcase == '-ExecutionPolicy'.downcase
78
+ end
79
+
80
+ execution_policy = execution_policy_specified ? provider_flags[execution_policy_index] : nil
81
+ end
82
+
83
+ context 'when running with an unspecified PowerShell version' do
84
+ let(:powershell_version) { nil }
85
+ it "sets the -ExecutionPolicy flag to 'Unrestricted' by default" do
86
+ expect(execution_policy_flag.downcase).to eq('unrestricted'.downcase)
87
+ end
62
88
  end
63
- end
64
89
 
65
- { '2.0' => 'Unrestricted',
66
- '2.5' => 'Unrestricted',
67
- '3.0' => 'Bypass',
68
- '3.6' => 'Bypass',
69
- '4.0' => 'Bypass',
70
- '5.0' => 'Bypass' }.each do | version_policy |
71
- let(:powershell_version) { version_policy[0].to_f }
72
- context "when running PowerShell version #{version_policy[0]}" do
90
+ { '2.0' => 'Unrestricted',
91
+ '2.5' => 'Unrestricted',
92
+ '3.0' => 'Bypass',
93
+ '3.6' => 'Bypass',
94
+ '4.0' => 'Bypass',
95
+ '5.0' => 'Bypass' }.each do | version_policy |
73
96
  let(:powershell_version) { version_policy[0].to_f }
74
- it "should set the -ExecutionPolicy flag to '#{version_policy[1]}'" do
75
- expect(execution_policy_flag.downcase).to eq(version_policy[1].downcase)
97
+ context "when running PowerShell version #{version_policy[0]}" do
98
+ let(:powershell_version) { version_policy[0].to_f }
99
+ it "sets the -ExecutionPolicy flag to '#{version_policy[1]}'" do
100
+ expect(execution_policy_flag.downcase).to eq(version_policy[1].downcase)
101
+ end
76
102
  end
77
103
  end
78
104
  end
@@ -79,7 +79,7 @@ describe Chef::Provider::RemoteDirectory do
79
79
  end
80
80
 
81
81
  it "configures access control on intermediate directorys" do
82
- directory_resource = @provider.send(:resource_for_directory, File.join(Dir.tmpdir, "intermediate_dir"))
82
+ directory_resource = @provider.send(:directory_resource, File.join(Dir.tmpdir, "intermediate_dir"))
83
83
  expect(directory_resource.path).to eq(File.join(Dir.tmpdir, "intermediate_dir"))
84
84
  expect(directory_resource.mode).to eq("0750")
85
85
  expect(directory_resource.group).to eq("wheel")
@@ -219,4 +219,3 @@ describe Chef::Provider::RemoteDirectory do
219
219
 
220
220
  end
221
221
  end
222
-
@@ -94,7 +94,7 @@ describe Chef::Provider::Service::Aix do
94
94
  end
95
95
 
96
96
  it "service is a group" do
97
- expect(@provider).to receive(:shell_out!).with("lssrc -g chef").and_return(@status)
97
+ expect(@provider).to receive(:shell_out).with("lssrc -g chef").and_return(@status)
98
98
  @provider.load_current_resource
99
99
  expect(@provider.instance_eval("@is_resource_group")).to be_truthy
100
100
  end
@@ -106,7 +106,7 @@ describe Chef::Provider::Service::Aix do
106
106
  end
107
107
 
108
108
  it "service is a group" do
109
- expect(@provider).to receive(:shell_out!).with("lssrc -g chef").and_return(@status)
109
+ expect(@provider).to receive(:shell_out).with("lssrc -g chef").and_return(@status)
110
110
  @provider.load_current_resource
111
111
  expect(@provider.instance_eval("@is_resource_group")).to be_truthy
112
112
  end
@@ -119,7 +119,7 @@ describe Chef::Provider::Service::Aix do
119
119
  end
120
120
 
121
121
  it "service is a subsystem" do
122
- expect(@provider).to receive(:shell_out!).with("lssrc -g chef").and_return(@group_status)
122
+ expect(@provider).to receive(:shell_out).with("lssrc -g chef").and_return(@group_status)
123
123
  expect(@provider).to receive(:shell_out!).with("lssrc -s chef").and_return(@service_status)
124
124
  @provider.load_current_resource
125
125
  expect(@provider.instance_eval("@is_resource_group")).to be_falsey
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # Author:: Lee Jensen (<ljensen@engineyard.com>)
3
3
  # Author:: AJ Christensen (<aj@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");
@@ -108,17 +108,17 @@ describe Chef::Provider::Service::Gentoo do
108
108
 
109
109
  it "should support the status command automatically" do
110
110
  @provider.load_current_resource
111
- expect(@new_resource.supports[:status]).to be_truthy
111
+ expect(@provider.supports[:status]).to be true
112
112
  end
113
113
 
114
114
  it "should support the restart command automatically" do
115
115
  @provider.load_current_resource
116
- expect(@new_resource.supports[:restart]).to be_truthy
116
+ expect(@provider.supports[:restart]).to be true
117
117
  end
118
118
 
119
119
  it "should not support the reload command automatically" do
120
120
  @provider.load_current_resource
121
- expect(@new_resource.supports[:reload]).not_to be_truthy
121
+ expect(@provider.supports[:reload]).to be_falsey
122
122
  end
123
123
 
124
124
  end
@@ -35,10 +35,12 @@ describe Chef::Provider::Service::Openbsd do
35
35
  node
36
36
  end
37
37
 
38
+ let(:supports) { {:status => false} }
39
+
38
40
  let(:new_resource) do
39
41
  new_resource = Chef::Resource::Service.new("sndiod")
40
42
  new_resource.pattern("sndiod")
41
- new_resource.supports({:status => false})
43
+ new_resource.supports(supports)
42
44
  new_resource
43
45
  end
44
46
 
@@ -106,9 +108,7 @@ describe Chef::Provider::Service::Openbsd do
106
108
  context "when the service supports status" do
107
109
  let(:status) { double(:stdout => "", :exitstatus => 0) }
108
110
 
109
- before do
110
- new_resource.supports({:status => true})
111
- end
111
+ let(:supports) { { :status => true } }
112
112
 
113
113
  it "should run '/etc/rc.d/service_name status'" do
114
114
  expect(provider).to receive(:shell_out).with("/etc/rc.d/#{new_resource.service_name} check").and_return(status)
@@ -305,10 +305,12 @@ describe Chef::Provider::Service::Openbsd do
305
305
  end
306
306
 
307
307
  describe Chef::Provider::Service::Openbsd, "restart_service" do
308
- it "should call 'restart' on the service_name if the resource supports it" do
309
- new_resource.supports({:restart => true})
310
- expect(provider).to receive(:shell_out_with_systems_locale!).with("/etc/rc.d/#{new_resource.service_name} restart")
311
- provider.restart_service()
308
+ context "when the new_resource supports restart" do
309
+ let(:supports) { { restart: true } }
310
+ it "should call 'restart' on the service_name if the resource supports it" do
311
+ expect(provider).to receive(:shell_out_with_systems_locale!).with("/etc/rc.d/#{new_resource.service_name} restart")
312
+ provider.restart_service()
313
+ end
312
314
  end
313
315
 
314
316
  it "should call the restart_command if one has been specified" do
@@ -64,24 +64,76 @@ describe "Chef::Provider::Service::Redhat" do
64
64
  end
65
65
 
66
66
  describe "load current resource" do
67
- it "sets the current enabled status to true if the service is enabled for any run level" do
67
+ before do
68
68
  status = double("Status", :exitstatus => 0, :stdout => "" , :stderr => "")
69
- expect(@provider).to receive(:shell_out).with("/sbin/service chef status").and_return(status)
69
+ allow(@provider).to receive(:shell_out).with("/sbin/service chef status").and_return(status)
70
+ end
71
+
72
+ it "sets supports[:status] to true by default" do
70
73
  chkconfig = double("Chkconfig", :exitstatus => 0, :stdout => "chef 0:off 1:off 2:off 3:off 4:off 5:on 6:off", :stderr => "")
71
74
  expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_return(chkconfig)
72
- expect(@provider.instance_variable_get("@service_missing")).to be_falsey
75
+ expect(@provider.service_missing).to be false
73
76
  @provider.load_current_resource
74
- expect(@current_resource.enabled).to be_truthy
77
+ expect(@provider.supports[:status]).to be true
78
+ end
79
+
80
+ it "lets the user override supports[:status] in the new_resource" do
81
+ @new_resource.supports( { status: false } )
82
+ @new_resource.pattern "myservice"
83
+ chkconfig = double("Chkconfig", :exitstatus => 0, :stdout => "chef 0:off 1:off 2:off 3:off 4:off 5:on 6:off", :stderr => "")
84
+ expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_return(chkconfig)
85
+ foo_out = double("ps_command", :exitstatus => 0, :stdout => "a line that matches myservice", :stderr => "")
86
+ expect(@provider).to receive(:shell_out!).with("foo").and_return(foo_out)
87
+ expect(@provider.service_missing).to be false
88
+ expect(@provider).not_to receive(:shell_out).with("/sbin/service chef status")
89
+ @provider.load_current_resource
90
+ expect(@provider.supports[:status]).to be false
91
+ end
92
+
93
+ it "sets the current enabled status to true if the service is enabled for any run level" do
94
+ chkconfig = double("Chkconfig", :exitstatus => 0, :stdout => "chef 0:off 1:off 2:off 3:off 4:off 5:on 6:off", :stderr => "")
95
+ expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_return(chkconfig)
96
+ expect(@provider.service_missing).to be false
97
+ @provider.load_current_resource
98
+ expect(@current_resource.enabled).to be true
75
99
  end
76
100
 
77
101
  it "sets the current enabled status to false if the regex does not match" do
78
- status = double("Status", :exitstatus => 0, :stdout => "" , :stderr => "")
79
- expect(@provider).to receive(:shell_out).with("/sbin/service chef status").and_return(status)
80
102
  chkconfig = double("Chkconfig", :exitstatus => 0, :stdout => "chef 0:off 1:off 2:off 3:off 4:off 5:off 6:off", :stderr => "")
81
103
  expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_return(chkconfig)
82
- expect(@provider.instance_variable_get("@service_missing")).to be_falsey
104
+ expect(@provider.service_missing).to be false
83
105
  expect(@provider.load_current_resource).to eql(@current_resource)
84
- expect(@current_resource.enabled).to be_falsey
106
+ expect(@current_resource.enabled).to be false
107
+ end
108
+
109
+ it "sets the current enabled status to true if the service is enabled at specified run levels" do
110
+ @new_resource.run_levels([1, 2])
111
+ chkconfig = double("Chkconfig", :exitstatus => 0, :stdout => "chef 0:off 1:on 2:on 3:off 4:off 5:off 6:off", :stderr => "")
112
+ expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_return(chkconfig)
113
+ expect(@provider.service_missing).to be false
114
+ @provider.load_current_resource
115
+ expect(@current_resource.enabled).to be true
116
+ expect(@provider.current_run_levels).to eql([1, 2])
117
+ end
118
+
119
+ it "sets the current enabled status to false if the service is enabled at a run level it should not" do
120
+ @new_resource.run_levels([1, 2])
121
+ chkconfig = double("Chkconfig", :exitstatus => 0, :stdout => "chef 0:off 1:on 2:on 3:on 4:off 5:off 6:off", :stderr => "")
122
+ expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_return(chkconfig)
123
+ expect(@provider.service_missing).to be false
124
+ @provider.load_current_resource
125
+ expect(@current_resource.enabled).to be false
126
+ expect(@provider.current_run_levels).to eql([1, 2, 3])
127
+ end
128
+
129
+ it "sets the current enabled status to false if the service is not enabled at specified run levels" do
130
+ @new_resource.run_levels([ 2 ])
131
+ chkconfig = double("Chkconfig", :exitstatus => 0, :stdout => "chef 0:off 1:on 2:off 3:off 4:off 5:off 6:off", :stderr => "")
132
+ expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --list chef", :returns => [0,1]).and_return(chkconfig)
133
+ expect(@provider.service_missing).to be false
134
+ @provider.load_current_resource
135
+ expect(@current_resource.enabled).to be false
136
+ expect(@provider.current_run_levels).to eql([1])
85
137
  end
86
138
  end
87
139
 
@@ -144,6 +196,28 @@ describe "Chef::Provider::Service::Redhat" do
144
196
  expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig #{@new_resource.service_name} on")
145
197
  @provider.enable_service
146
198
  end
199
+
200
+ it "should call chkconfig to add 'service_name' at specified run_levels" do
201
+ allow(@provider).to receive(:run_levels).and_return([1, 2])
202
+ expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --level 12 #{@new_resource.service_name} on")
203
+ @provider.enable_service
204
+ end
205
+
206
+ it "should call chkconfig to add 'service_name' at specified run_levels when run_levels do not match" do
207
+ allow(@provider).to receive(:run_levels).and_return([1, 2])
208
+ allow(@provider).to receive(:current_run_levels).and_return([1, 3])
209
+ expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --level 12 #{@new_resource.service_name} on")
210
+ expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --level 3 #{@new_resource.service_name} off")
211
+ @provider.enable_service
212
+ end
213
+
214
+ it "should call chkconfig to add 'service_name' at specified run_levels if there is an extra run_level" do
215
+ allow(@provider).to receive(:run_levels).and_return([1, 2])
216
+ allow(@provider).to receive(:current_run_levels).and_return([1, 2, 3])
217
+ expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --level 12 #{@new_resource.service_name} on")
218
+ expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --level 3 #{@new_resource.service_name} off")
219
+ @provider.enable_service
220
+ end
147
221
  end
148
222
 
149
223
  describe "disable_service" do
@@ -151,6 +225,12 @@ describe "Chef::Provider::Service::Redhat" do
151
225
  expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig #{@new_resource.service_name} off")
152
226
  @provider.disable_service
153
227
  end
228
+
229
+ it "should call chkconfig to del 'service_name' at specified run_levels" do
230
+ allow(@provider).to receive(:run_levels).and_return([1, 2])
231
+ expect(@provider).to receive(:shell_out!).with("/sbin/chkconfig --level 12 #{@new_resource.service_name} off")
232
+ @provider.disable_service
233
+ end
154
234
  end
155
235
 
156
236
  end
@@ -19,6 +19,10 @@
19
19
  require 'spec_helper'
20
20
 
21
21
  describe Chef::Provider::Service::Upstart do
22
+ let(:shell_out_success) do
23
+ double('shell_out_with_systems_locale', :exitstatus => 0, :error? => false)
24
+ end
25
+
22
26
  before(:each) do
23
27
  @node =Chef::Node.new
24
28
  @node.name('upstarter')
@@ -173,7 +177,7 @@ describe Chef::Provider::Service::Upstart do
173
177
  end
174
178
 
175
179
  it "should run the services status command if one has been specified" do
176
- allow(@provider).to receive(:shell_out!).with("/bin/chefhasmonkeypants status").and_return(0)
180
+ allow(@provider).to receive(:shell_out!).with("/bin/chefhasmonkeypants status").and_return(shell_out_success)
177
181
  expect(@current_resource).to receive(:running).with(true)
178
182
  @provider.load_current_resource
179
183
  end
@@ -246,7 +250,7 @@ describe Chef::Provider::Service::Upstart do
246
250
  end
247
251
 
248
252
  it "should call '/sbin/start service_name' if no start command is specified" do
249
- expect(@provider).to receive(:shell_out_with_systems_locale!).with("/sbin/start #{@new_resource.service_name}").and_return(0)
253
+ expect(@provider).to receive(:shell_out_with_systems_locale!).with("/sbin/start #{@new_resource.service_name}").and_return(shell_out_success)
250
254
  @provider.start_service()
251
255
  end
252
256
 
@@ -261,7 +265,7 @@ describe Chef::Provider::Service::Upstart do
261
265
  @new_resource.parameters({ "OSD_ID" => "2" })
262
266
  @provider = Chef::Provider::Service::Upstart.new(@new_resource, @run_context)
263
267
  @provider.current_resource = @current_resource
264
- expect(@provider).to receive(:shell_out_with_systems_locale!).with("/sbin/start rsyslog OSD_ID=2").and_return(0)
268
+ expect(@provider).to receive(:shell_out_with_systems_locale!).with("/sbin/start rsyslog OSD_ID=2").and_return(shell_out_success)
265
269
  @provider.start_service()
266
270
  end
267
271
 
@@ -274,13 +278,13 @@ describe Chef::Provider::Service::Upstart do
274
278
 
275
279
  it "should call '/sbin/restart service_name' if no restart command is specified" do
276
280
  allow(@current_resource).to receive(:running).and_return(true)
277
- expect(@provider).to receive(:shell_out_with_systems_locale!).with("/sbin/restart #{@new_resource.service_name}").and_return(0)
281
+ expect(@provider).to receive(:shell_out_with_systems_locale!).with("/sbin/restart #{@new_resource.service_name}").and_return(shell_out_success)
278
282
  @provider.restart_service()
279
283
  end
280
284
 
281
285
  it "should call '/sbin/start service_name' if restart_service is called for a stopped service" do
282
286
  allow(@current_resource).to receive(:running).and_return(false)
283
- expect(@provider).to receive(:shell_out_with_systems_locale!).with("/sbin/start #{@new_resource.service_name}").and_return(0)
287
+ expect(@provider).to receive(:shell_out_with_systems_locale!).with("/sbin/start #{@new_resource.service_name}").and_return(shell_out_success)
284
288
  @provider.restart_service()
285
289
  end
286
290
 
@@ -293,7 +297,7 @@ describe Chef::Provider::Service::Upstart do
293
297
 
294
298
  it "should call '/sbin/reload service_name' if no reload command is specified" do
295
299
  allow(@current_resource).to receive(:running).and_return(true)
296
- expect(@provider).to receive(:shell_out_with_systems_locale!).with("/sbin/reload #{@new_resource.service_name}").and_return(0)
300
+ expect(@provider).to receive(:shell_out_with_systems_locale!).with("/sbin/reload #{@new_resource.service_name}").and_return(shell_out_success)
297
301
  @provider.reload_service()
298
302
  end
299
303
 
@@ -306,7 +310,7 @@ describe Chef::Provider::Service::Upstart do
306
310
 
307
311
  it "should call '/sbin/stop service_name' if no stop command is specified" do
308
312
  allow(@current_resource).to receive(:running).and_return(true)
309
- expect(@provider).to receive(:shell_out_with_systems_locale!).with("/sbin/stop #{@new_resource.service_name}").and_return(0)
313
+ expect(@provider).to receive(:shell_out_with_systems_locale!).with("/sbin/stop #{@new_resource.service_name}").and_return(shell_out_success)
310
314
  @provider.stop_service()
311
315
  end
312
316
 
@@ -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