chef 12.4.0.rc.0-universal-mingw32 → 12.4.0.rc.2-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (298) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +12 -1
  3. data/lib/chef/api_client.rb +130 -26
  4. data/lib/chef/application.rb +0 -1
  5. data/lib/chef/application/client.rb +8 -19
  6. data/lib/chef/audit/audit_reporter.rb +12 -7
  7. data/lib/chef/audit/logger.rb +36 -0
  8. data/lib/chef/audit/runner.rb +4 -2
  9. data/lib/chef/chef_class.rb +62 -11
  10. data/lib/chef/client.rb +587 -207
  11. data/lib/chef/config.rb +0 -1
  12. data/lib/chef/dsl/recipe.rb +45 -56
  13. data/lib/chef/dsl/resources.rb +3 -2
  14. data/lib/chef/event_dispatch/base.rb +7 -2
  15. data/lib/chef/exceptions.rb +4 -1
  16. data/lib/chef/file_content_management/deploy/mv_windows.rb +16 -6
  17. data/lib/chef/formatters/doc.rb +15 -7
  18. data/lib/chef/formatters/error_inspectors/api_error_formatting.rb +10 -7
  19. data/lib/chef/guard_interpreter/default_guard_interpreter.rb +2 -0
  20. data/lib/chef/guard_interpreter/resource_guard_interpreter.rb +4 -1
  21. data/lib/chef/http/authenticator.rb +7 -2
  22. data/lib/chef/knife.rb +16 -4
  23. data/lib/chef/knife/client_create.rb +55 -31
  24. data/lib/chef/knife/core/generic_presenter.rb +1 -1
  25. data/lib/chef/knife/core/subcommand_loader.rb +1 -1
  26. data/lib/chef/knife/osc_user_create.rb +97 -0
  27. data/lib/chef/knife/osc_user_delete.rb +51 -0
  28. data/lib/chef/knife/osc_user_edit.rb +58 -0
  29. data/lib/chef/knife/osc_user_list.rb +47 -0
  30. data/lib/chef/knife/osc_user_reregister.rb +64 -0
  31. data/lib/chef/knife/osc_user_show.rb +54 -0
  32. data/lib/chef/knife/user_create.rb +95 -36
  33. data/lib/chef/knife/user_delete.rb +52 -2
  34. data/lib/chef/knife/user_edit.rb +37 -7
  35. data/lib/chef/knife/user_list.rb +3 -0
  36. data/lib/chef/knife/user_reregister.rb +39 -8
  37. data/lib/chef/knife/user_show.rb +30 -1
  38. data/lib/chef/mixin/api_version_request_handling.rb +66 -0
  39. data/lib/chef/mixin/convert_to_class_name.rb +10 -4
  40. data/lib/chef/mixin/deprecation.rb +24 -0
  41. data/lib/chef/mixin/powershell_out.rb +98 -0
  42. data/lib/chef/mixin/provides.rb +5 -18
  43. data/lib/chef/mixin/uris.rb +11 -0
  44. data/lib/chef/mixin/windows_architecture_helper.rb +5 -2
  45. data/lib/chef/mixin/windows_env_helper.rb +11 -2
  46. data/lib/chef/node_map.rb +130 -75
  47. data/lib/chef/osc_user.rb +194 -0
  48. data/lib/chef/platform/provider_mapping.rb +2 -269
  49. data/lib/chef/platform/provider_priority_map.rb +6 -69
  50. data/lib/chef/platform/query_helpers.rb +5 -0
  51. data/lib/chef/platform/resource_priority_map.rb +12 -15
  52. data/lib/chef/policy_builder/policyfile.rb +1 -0
  53. data/lib/chef/provider.rb +19 -0
  54. data/lib/chef/provider/directory.rb +3 -0
  55. data/lib/chef/provider/dsc_resource.rb +8 -1
  56. data/lib/chef/provider/file.rb +1 -0
  57. data/lib/chef/provider/group/aix.rb +1 -0
  58. data/lib/chef/provider/group/dscl.rb +1 -1
  59. data/lib/chef/provider/group/gpasswd.rb +1 -0
  60. data/lib/chef/provider/group/groupmod.rb +1 -1
  61. data/lib/chef/provider/group/pw.rb +1 -0
  62. data/lib/chef/provider/group/suse.rb +2 -0
  63. data/lib/chef/provider/group/usermod.rb +2 -1
  64. data/lib/chef/provider/group/windows.rb +1 -1
  65. data/lib/chef/provider/ifconfig.rb +2 -0
  66. data/lib/chef/provider/ifconfig/aix.rb +1 -0
  67. data/lib/chef/provider/ifconfig/debian.rb +2 -0
  68. data/lib/chef/provider/ifconfig/redhat.rb +1 -0
  69. data/lib/chef/provider/lwrp_base.rb +4 -0
  70. data/lib/chef/provider/mount.rb +0 -1
  71. data/lib/chef/provider/mount/aix.rb +1 -0
  72. data/lib/chef/provider/mount/mount.rb +2 -0
  73. data/lib/chef/provider/mount/solaris.rb +2 -0
  74. data/lib/chef/provider/package.rb +55 -0
  75. data/lib/chef/provider/package/aix.rb +7 -7
  76. data/lib/chef/provider/package/apt.rb +3 -3
  77. data/lib/chef/provider/package/dpkg.rb +4 -4
  78. data/lib/chef/provider/package/easy_install.rb +5 -5
  79. data/lib/chef/provider/package/freebsd/base.rb +2 -2
  80. data/lib/chef/provider/package/freebsd/pkg.rb +6 -6
  81. data/lib/chef/provider/package/freebsd/pkgng.rb +5 -5
  82. data/lib/chef/provider/package/freebsd/port.rb +4 -4
  83. data/lib/chef/provider/package/homebrew.rb +2 -2
  84. data/lib/chef/provider/package/ips.rb +4 -4
  85. data/lib/chef/provider/package/macports.rb +5 -6
  86. data/lib/chef/provider/package/openbsd.rb +4 -5
  87. data/lib/chef/provider/package/pacman.rb +4 -4
  88. data/lib/chef/provider/package/portage.rb +2 -0
  89. data/lib/chef/provider/package/rpm.rb +7 -8
  90. data/lib/chef/provider/package/rubygems.rb +5 -12
  91. data/lib/chef/provider/package/smartos.rb +4 -4
  92. data/lib/chef/provider/package/solaris.rb +7 -7
  93. data/lib/chef/provider/package/windows/msi.rb +1 -1
  94. data/lib/chef/provider/package/yum.rb +4 -6
  95. data/lib/chef/provider/package/zypper.rb +16 -14
  96. data/lib/chef/provider/powershell_script.rb +129 -47
  97. data/lib/chef/provider/remote_file/content.rb +4 -1
  98. data/lib/chef/provider/remote_file/local_file.rb +10 -4
  99. data/lib/chef/provider/service.rb +44 -0
  100. data/lib/chef/provider/service/freebsd.rb +1 -1
  101. data/lib/chef/provider/service/init.rb +1 -0
  102. data/lib/chef/provider/service/macosx.rb +1 -1
  103. data/lib/chef/provider/service/windows.rb +0 -1
  104. data/lib/chef/provider/user.rb +1 -1
  105. data/lib/chef/provider/user/aix.rb +3 -2
  106. data/lib/chef/provider/user/pw.rb +1 -0
  107. data/lib/chef/provider/user/solaris.rb +2 -0
  108. data/lib/chef/provider/user/useradd.rb +1 -0
  109. data/lib/chef/provider_resolver.rb +87 -134
  110. data/lib/chef/resource.rb +274 -68
  111. data/lib/chef/resource/apt_package.rb +0 -2
  112. data/lib/chef/resource/bash.rb +0 -2
  113. data/lib/chef/resource/batch.rb +1 -1
  114. data/lib/chef/resource/bff_package.rb +0 -7
  115. data/lib/chef/resource/breakpoint.rb +3 -6
  116. data/lib/chef/resource/chef_gem.rb +0 -3
  117. data/lib/chef/resource/cookbook_file.rb +1 -3
  118. data/lib/chef/resource/cron.rb +2 -4
  119. data/lib/chef/resource/csh.rb +0 -2
  120. data/lib/chef/resource/deploy.rb +9 -6
  121. data/lib/chef/resource/deploy_revision.rb +0 -14
  122. data/lib/chef/resource/directory.rb +2 -4
  123. data/lib/chef/resource/dpkg_package.rb +0 -5
  124. data/lib/chef/resource/dsc_resource.rb +2 -3
  125. data/lib/chef/resource/dsc_script.rb +2 -3
  126. data/lib/chef/resource/easy_install_package.rb +0 -7
  127. data/lib/chef/resource/env.rb +3 -3
  128. data/lib/chef/resource/erl_call.rb +2 -5
  129. data/lib/chef/resource/execute.rb +2 -4
  130. data/lib/chef/resource/file.rb +2 -4
  131. data/lib/chef/resource/freebsd_package.rb +0 -5
  132. data/lib/chef/resource/gem_package.rb +0 -3
  133. data/lib/chef/resource/git.rb +0 -3
  134. data/lib/chef/resource/group.rb +2 -4
  135. data/lib/chef/resource/homebrew_package.rb +0 -2
  136. data/lib/chef/resource/http_request.rb +3 -4
  137. data/lib/chef/resource/ifconfig.rb +3 -4
  138. data/lib/chef/resource/ips_package.rb +2 -2
  139. data/lib/chef/resource/link.rb +3 -5
  140. data/lib/chef/resource/log.rb +2 -4
  141. data/lib/chef/resource/lwrp_base.rb +10 -61
  142. data/lib/chef/resource/macosx_service.rb +1 -2
  143. data/lib/chef/resource/macports_package.rb +0 -7
  144. data/lib/chef/resource/mdadm.rb +2 -5
  145. data/lib/chef/resource/mount.rb +2 -4
  146. data/lib/chef/resource/ohai.rb +2 -4
  147. data/lib/chef/resource/openbsd_package.rb +0 -6
  148. data/lib/chef/resource/package.rb +9 -6
  149. data/lib/chef/resource/pacman_package.rb +0 -7
  150. data/lib/chef/resource/paludis_package.rb +2 -3
  151. data/lib/chef/resource/perl.rb +0 -3
  152. data/lib/chef/resource/portage_package.rb +0 -3
  153. data/lib/chef/resource/powershell_script.rb +1 -2
  154. data/lib/chef/resource/python.rb +0 -3
  155. data/lib/chef/resource/reboot.rb +1 -3
  156. data/lib/chef/resource/registry_key.rb +3 -5
  157. data/lib/chef/resource/remote_directory.rb +3 -5
  158. data/lib/chef/resource/remote_file.rb +4 -5
  159. data/lib/chef/resource/route.rb +3 -5
  160. data/lib/chef/resource/rpm_package.rb +0 -2
  161. data/lib/chef/resource/ruby.rb +0 -4
  162. data/lib/chef/resource/ruby_block.rb +2 -4
  163. data/lib/chef/resource/scm.rb +3 -5
  164. data/lib/chef/resource/script.rb +0 -3
  165. data/lib/chef/resource/service.rb +3 -5
  166. data/lib/chef/resource/smartos_package.rb +0 -9
  167. data/lib/chef/resource/solaris_package.rb +0 -10
  168. data/lib/chef/resource/subversion.rb +1 -3
  169. data/lib/chef/resource/template.rb +0 -4
  170. data/lib/chef/resource/timestamped_deploy.rb +0 -4
  171. data/lib/chef/resource/user.rb +2 -5
  172. data/lib/chef/resource/whyrun_safe_ruby_block.rb +0 -7
  173. data/lib/chef/resource/windows_package.rb +3 -3
  174. data/lib/chef/resource/windows_script.rb +2 -2
  175. data/lib/chef/resource/windows_service.rb +3 -3
  176. data/lib/chef/resource/yum_package.rb +0 -3
  177. data/lib/chef/resource/zypper_package.rb +27 -0
  178. data/lib/chef/resource_builder.rb +7 -0
  179. data/lib/chef/resource_reporter.rb +1 -1
  180. data/lib/chef/resource_resolver.rb +108 -62
  181. data/lib/chef/resources.rb +1 -0
  182. data/lib/chef/rest.rb +1 -0
  183. data/lib/chef/server_api.rb +2 -0
  184. data/lib/chef/user.rb +193 -42
  185. data/lib/chef/util/backup.rb +9 -1
  186. data/lib/chef/util/path_helper.rb +0 -1
  187. data/lib/chef/version.rb +1 -1
  188. data/spec/functional/audit/runner_spec.rb +22 -42
  189. data/spec/functional/mixin/powershell_out_spec.rb +43 -0
  190. data/spec/functional/resource/execute_spec.rb +9 -2
  191. data/spec/functional/resource/file_spec.rb +25 -0
  192. data/spec/functional/resource/group_spec.rb +5 -0
  193. data/spec/functional/resource/link_spec.rb +5 -11
  194. data/spec/functional/resource/powershell_spec.rb +40 -5
  195. data/spec/functional/resource/user/useradd_spec.rb +10 -18
  196. data/spec/integration/recipes/lwrp_spec.rb +57 -0
  197. data/spec/integration/recipes/provider_choice.rb +2 -7
  198. data/spec/integration/recipes/recipe_dsl_spec.rb +517 -19
  199. data/spec/spec_helper.rb +1 -1
  200. data/spec/support/lib/chef/provider/openldap_includer.rb +29 -0
  201. data/spec/support/lib/chef/resource/cat.rb +0 -2
  202. data/spec/support/lib/chef/resource/one_two_three_four.rb +0 -6
  203. data/spec/support/lib/chef/resource/openldap_includer.rb +27 -0
  204. data/spec/support/lib/chef/resource/with_state.rb +0 -9
  205. data/spec/support/lib/chef/resource/zen_follower.rb +0 -6
  206. data/spec/support/lib/chef/resource/zen_master.rb +1 -6
  207. data/spec/support/shared/context/client.rb +277 -0
  208. data/spec/support/shared/examples/client.rb +53 -0
  209. data/spec/support/shared/functional/file_resource.rb +0 -4
  210. data/spec/support/shared/functional/securable_resource.rb +0 -24
  211. data/spec/support/shared/functional/securable_resource_with_reporting.rb +4 -4
  212. data/spec/support/shared/functional/windows_script.rb +1 -1
  213. data/spec/support/shared/unit/api_versioning.rb +77 -0
  214. data/spec/support/shared/unit/knife_shared.rb +40 -0
  215. data/spec/support/shared/unit/user_and_client_shared.rb +115 -0
  216. data/spec/unit/api_client_spec.rb +189 -14
  217. data/spec/unit/application/client_spec.rb +0 -5
  218. data/spec/unit/audit/audit_reporter_spec.rb +58 -14
  219. data/spec/unit/audit/logger_spec.rb +42 -0
  220. data/spec/unit/audit/runner_spec.rb +2 -2
  221. data/spec/unit/chef_fs/file_pattern_spec.rb +3 -15
  222. data/spec/unit/client_spec.rb +58 -374
  223. data/spec/unit/cookbook_spec.rb +0 -9
  224. data/spec/unit/cookbook_version_spec.rb +0 -20
  225. data/spec/unit/deprecation_spec.rb +55 -0
  226. data/spec/unit/dsl/resources_spec.rb +85 -0
  227. data/spec/unit/exceptions_spec.rb +2 -2
  228. data/spec/unit/file_content_management/deploy/mv_windows_spec.rb +60 -0
  229. data/spec/unit/formatters/doc_spec.rb +46 -0
  230. data/spec/unit/formatters/error_inspectors/api_error_formatting_spec.rb +12 -10
  231. data/spec/unit/guard_interpreter/resource_guard_interpreter_spec.rb +8 -0
  232. data/spec/unit/http/authenticator_spec.rb +11 -2
  233. data/spec/unit/knife/client_create_spec.rb +122 -51
  234. data/spec/unit/knife/core/subcommand_loader_spec.rb +19 -3
  235. data/spec/unit/knife/core/ui_spec.rb +14 -0
  236. data/spec/unit/knife/osc_user_create_spec.rb +93 -0
  237. data/spec/unit/knife/osc_user_delete_spec.rb +44 -0
  238. data/spec/unit/knife/osc_user_edit_spec.rb +52 -0
  239. data/spec/unit/knife/osc_user_list_spec.rb +37 -0
  240. data/spec/unit/knife/osc_user_reregister_spec.rb +58 -0
  241. data/spec/unit/knife/osc_user_show_spec.rb +46 -0
  242. data/spec/unit/knife/user_create_spec.rb +177 -51
  243. data/spec/unit/knife/user_delete_spec.rb +34 -8
  244. data/spec/unit/knife/user_edit_spec.rb +31 -12
  245. data/spec/unit/knife/user_list_spec.rb +7 -3
  246. data/spec/unit/knife/user_reregister_spec.rb +38 -17
  247. data/spec/unit/knife/user_show_spec.rb +35 -11
  248. data/spec/unit/knife_spec.rb +10 -4
  249. data/spec/unit/lwrp_spec.rb +228 -54
  250. data/spec/unit/mixin/api_version_request_handling_spec.rb +127 -0
  251. data/spec/unit/mixin/command_spec.rb +1 -2
  252. data/spec/unit/mixin/powershell_out_spec.rb +70 -0
  253. data/spec/unit/mixin/uris_spec.rb +23 -11
  254. data/spec/unit/node_map_spec.rb +4 -1
  255. data/spec/unit/osc_user_spec.rb +276 -0
  256. data/spec/unit/platform_spec.rb +0 -60
  257. data/spec/unit/provider/deploy_spec.rb +1 -1
  258. data/spec/unit/provider/directory_spec.rb +199 -135
  259. data/spec/unit/provider/ifconfig/debian_spec.rb +0 -10
  260. data/spec/unit/provider/package/aix_spec.rb +16 -16
  261. data/spec/unit/provider/package/dpkg_spec.rb +2 -2
  262. data/spec/unit/provider/package/freebsd/pkg_spec.rb +13 -13
  263. data/spec/unit/provider/package/freebsd/pkgng_spec.rb +9 -9
  264. data/spec/unit/provider/package/freebsd/port_spec.rb +7 -7
  265. data/spec/unit/provider/package/ips_spec.rb +22 -22
  266. data/spec/unit/provider/package/macports_spec.rb +10 -10
  267. data/spec/unit/provider/package/openbsd_spec.rb +4 -26
  268. data/spec/unit/provider/package/pacman_spec.rb +5 -5
  269. data/spec/unit/provider/package/rpm_spec.rb +14 -14
  270. data/spec/unit/provider/package/rubygems_spec.rb +10 -44
  271. data/spec/unit/provider/package/smartos_spec.rb +4 -4
  272. data/spec/unit/provider/package/solaris_spec.rb +11 -11
  273. data/spec/unit/provider/package/zypper_spec.rb +125 -90
  274. data/spec/unit/provider/package_spec.rb +34 -0
  275. data/spec/unit/provider/powershell_spec.rb +53 -11
  276. data/spec/unit/provider/remote_directory_spec.rb +2 -2
  277. data/spec/unit/provider/remote_file/local_file_spec.rb +25 -6
  278. data/spec/unit/provider/service/freebsd_service_spec.rb +0 -12
  279. data/spec/unit/provider/user_spec.rb +3 -3
  280. data/spec/unit/provider_resolver_spec.rb +463 -327
  281. data/spec/unit/recipe_spec.rb +42 -15
  282. data/spec/unit/resource/breakpoint_spec.rb +1 -1
  283. data/spec/unit/resource/erl_call_spec.rb +1 -1
  284. data/spec/unit/resource/file_spec.rb +1 -1
  285. data/spec/unit/resource/ifconfig_spec.rb +10 -6
  286. data/spec/unit/resource/remote_file_spec.rb +5 -0
  287. data/spec/unit/resource/route_spec.rb +1 -1
  288. data/spec/unit/resource/ruby_block_spec.rb +2 -2
  289. data/spec/unit/resource/template_spec.rb +1 -1
  290. data/spec/unit/resource/timestamped_deploy_spec.rb +1 -2
  291. data/spec/unit/resource/windows_service_spec.rb +1 -1
  292. data/spec/unit/resource_spec.rb +99 -13
  293. data/spec/unit/rest_spec.rb +5 -5
  294. data/spec/unit/run_context_spec.rb +41 -0
  295. data/spec/unit/runner_spec.rb +2 -2
  296. data/spec/unit/user_spec.rb +406 -93
  297. data/tasks/maintainers.rb +69 -0
  298. metadata +37 -4
@@ -19,21 +19,47 @@
19
19
  require 'spec_helper'
20
20
 
21
21
  describe Chef::Knife::UserDelete do
22
+ let(:knife) { Chef::Knife::UserDelete.new }
23
+ let(:user) { double('user_object') }
24
+ let(:stdout) { StringIO.new }
25
+
22
26
  before(:each) do
23
27
  Chef::Knife::UserDelete.load_deps
24
- @knife = Chef::Knife::UserDelete.new
25
- @knife.name_args = [ 'my_user' ]
28
+ knife.name_args = [ 'my_user' ]
29
+ allow(Chef::User).to receive(:load).and_return(user)
30
+ allow(user).to receive(:username).and_return('my_user')
31
+ allow(knife.ui).to receive(:stderr).and_return(stdout)
32
+ allow(knife.ui).to receive(:stdout).and_return(stdout)
33
+ end
34
+
35
+ # delete this once OSC11 support is gone
36
+ context "when the username field is not supported by the server" do
37
+ before do
38
+ allow(knife).to receive(:run_osc_11_user_delete).and_raise(SystemExit)
39
+ allow(user).to receive(:username).and_return(nil)
40
+ end
41
+
42
+ it "displays the osc warning" do
43
+ expect(knife.ui).to receive(:warn).with(knife.osc_11_warning)
44
+ expect{ knife.run }.to raise_error(SystemExit)
45
+ end
46
+
47
+ it "forwards the command to knife osc_user edit" do
48
+ expect(knife).to receive(:run_osc_11_user_delete)
49
+ expect{ knife.run }.to raise_error(SystemExit)
50
+ end
26
51
  end
27
52
 
28
53
  it 'deletes the user' do
29
- expect(@knife).to receive(:delete_object).with(Chef::User, 'my_user')
30
- @knife.run
54
+ #expect(knife).to receive(:delete_object).with(Chef::User, 'my_user')
55
+ expect(knife).to receive(:delete_object).with('my_user')
56
+ knife.run
31
57
  end
32
58
 
33
59
  it 'prints usage and exits when a user name is not provided' do
34
- @knife.name_args = []
35
- expect(@knife).to receive(:show_usage)
36
- expect(@knife.ui).to receive(:fatal)
37
- expect { @knife.run }.to raise_error(SystemExit)
60
+ knife.name_args = []
61
+ expect(knife).to receive(:show_usage)
62
+ expect(knife.ui).to receive(:fatal)
63
+ expect { knife.run }.to raise_error(SystemExit)
38
64
  end
39
65
  end
@@ -19,29 +19,48 @@
19
19
  require 'spec_helper'
20
20
 
21
21
  describe Chef::Knife::UserEdit do
22
+ let(:knife) { Chef::Knife::UserEdit.new }
23
+
22
24
  before(:each) do
23
25
  @stderr = StringIO.new
24
26
  @stdout = StringIO.new
25
27
 
26
28
  Chef::Knife::UserEdit.load_deps
27
- @knife = Chef::Knife::UserEdit.new
28
- allow(@knife.ui).to receive(:stderr).and_return(@stderr)
29
- allow(@knife.ui).to receive(:stdout).and_return(@stdout)
30
- @knife.name_args = [ 'my_user' ]
31
- @knife.config[:disable_editing] = true
29
+ allow(knife.ui).to receive(:stderr).and_return(@stderr)
30
+ allow(knife.ui).to receive(:stdout).and_return(@stdout)
31
+ knife.name_args = [ 'my_user' ]
32
+ knife.config[:disable_editing] = true
33
+ end
34
+
35
+ # delete this once OSC11 support is gone
36
+ context "when the username field is not supported by the server" do
37
+ before do
38
+ allow(knife).to receive(:run_osc_11_user_edit).and_raise(SystemExit)
39
+ allow(Chef::User).to receive(:load).and_return({"username" => nil})
40
+ end
41
+
42
+ it "displays the osc warning" do
43
+ expect(knife.ui).to receive(:warn).with(knife.osc_11_warning)
44
+ expect{ knife.run }.to raise_error(SystemExit)
45
+ end
46
+
47
+ it "forwards the command to knife osc_user edit" do
48
+ expect(knife).to receive(:run_osc_11_user_edit)
49
+ expect{ knife.run }.to raise_error(SystemExit)
50
+ end
32
51
  end
33
52
 
34
53
  it 'loads and edits the user' do
35
- data = { :name => "my_user" }
54
+ data = { "username" => "my_user" }
36
55
  allow(Chef::User).to receive(:load).with("my_user").and_return(data)
37
- expect(@knife).to receive(:edit_data).with(data).and_return(data)
38
- @knife.run
56
+ expect(knife).to receive(:edit_data).with(data).and_return(data)
57
+ knife.run
39
58
  end
40
59
 
41
60
  it 'prints usage and exits when a user name is not provided' do
42
- @knife.name_args = []
43
- expect(@knife).to receive(:show_usage)
44
- expect(@knife.ui).to receive(:fatal)
45
- expect { @knife.run }.to raise_error(SystemExit)
61
+ knife.name_args = []
62
+ expect(knife).to receive(:show_usage)
63
+ expect(knife.ui).to receive(:fatal)
64
+ expect { knife.run }.to raise_error(SystemExit)
46
65
  end
47
66
  end
@@ -19,14 +19,18 @@
19
19
  require 'spec_helper'
20
20
 
21
21
  describe Chef::Knife::UserList do
22
+ let(:knife) { Chef::Knife::UserList.new }
23
+ let(:stdout) { StringIO.new }
24
+
22
25
  before(:each) do
23
26
  Chef::Knife::UserList.load_deps
24
- @knife = Chef::Knife::UserList.new
27
+ allow(knife.ui).to receive(:stderr).and_return(stdout)
28
+ allow(knife.ui).to receive(:stdout).and_return(stdout)
25
29
  end
26
30
 
27
31
  it 'lists the users' do
28
32
  expect(Chef::User).to receive(:list)
29
- expect(@knife).to receive(:format_list_for_display)
30
- @knife.run
33
+ expect(knife).to receive(:format_list_for_display)
34
+ knife.run
31
35
  end
32
36
  end
@@ -19,35 +19,56 @@
19
19
  require 'spec_helper'
20
20
 
21
21
  describe Chef::Knife::UserReregister do
22
- before(:each) do
22
+ let(:knife) { Chef::Knife::UserReregister.new }
23
+ let(:user_mock) { double('user_mock', :private_key => "private_key") }
24
+ let(:stdout) { StringIO.new }
25
+
26
+ before do
23
27
  Chef::Knife::UserReregister.load_deps
24
- @knife = Chef::Knife::UserReregister.new
25
- @knife.name_args = [ 'a_user' ]
26
- @user_mock = double('user_mock', :private_key => "private_key")
27
- allow(Chef::User).to receive(:load).and_return(@user_mock)
28
- @stdout = StringIO.new
29
- allow(@knife.ui).to receive(:stdout).and_return(@stdout)
28
+ knife.name_args = [ 'a_user' ]
29
+ allow(Chef::User).to receive(:load).and_return(user_mock)
30
+ allow(knife.ui).to receive(:stdout).and_return(stdout)
31
+ allow(knife.ui).to receive(:stderr).and_return(stdout)
32
+ allow(user_mock).to receive(:username).and_return('a_user')
33
+ end
34
+
35
+ # delete this once OSC11 support is gone
36
+ context "when the username field is not supported by the server" do
37
+ before do
38
+ allow(knife).to receive(:run_osc_11_user_reregister).and_raise(SystemExit)
39
+ allow(user_mock).to receive(:username).and_return(nil)
40
+ end
41
+
42
+ it "displays the osc warning" do
43
+ expect(knife.ui).to receive(:warn).with(knife.osc_11_warning)
44
+ expect{ knife.run }.to raise_error(SystemExit)
45
+ end
46
+
47
+ it "forwards the command to knife osc_user edit" do
48
+ expect(knife).to receive(:run_osc_11_user_reregister)
49
+ expect{ knife.run }.to raise_error(SystemExit)
50
+ end
30
51
  end
31
52
 
32
53
  it 'prints usage and exits when a user name is not provided' do
33
- @knife.name_args = []
34
- expect(@knife).to receive(:show_usage)
35
- expect(@knife.ui).to receive(:fatal)
36
- expect { @knife.run }.to raise_error(SystemExit)
54
+ knife.name_args = []
55
+ expect(knife).to receive(:show_usage)
56
+ expect(knife.ui).to receive(:fatal)
57
+ expect { knife.run }.to raise_error(SystemExit)
37
58
  end
38
59
 
39
60
  it 'reregisters the user and prints the key' do
40
- expect(@user_mock).to receive(:reregister).and_return(@user_mock)
41
- @knife.run
42
- expect(@stdout.string).to match( /private_key/ )
61
+ expect(user_mock).to receive(:reregister).and_return(user_mock)
62
+ knife.run
63
+ expect(stdout.string).to match( /private_key/ )
43
64
  end
44
65
 
45
66
  it 'writes the private key to a file when --file is specified' do
46
- expect(@user_mock).to receive(:reregister).and_return(@user_mock)
47
- @knife.config[:file] = '/tmp/a_file'
67
+ expect(user_mock).to receive(:reregister).and_return(user_mock)
68
+ knife.config[:file] = '/tmp/a_file'
48
69
  filehandle = StringIO.new
49
70
  expect(File).to receive(:open).with('/tmp/a_file', 'w').and_yield(filehandle)
50
- @knife.run
71
+ knife.run
51
72
  expect(filehandle.string).to eq("private_key")
52
73
  end
53
74
  end
@@ -19,23 +19,47 @@
19
19
  require 'spec_helper'
20
20
 
21
21
  describe Chef::Knife::UserShow do
22
- before(:each) do
22
+ let(:knife) { Chef::Knife::UserShow.new }
23
+ let(:user_mock) { double('user_mock') }
24
+ let(:stdout) { StringIO.new }
25
+
26
+ before do
23
27
  Chef::Knife::UserShow.load_deps
24
- @knife = Chef::Knife::UserShow.new
25
- @knife.name_args = [ 'my_user' ]
26
- @user_mock = double('user_mock')
28
+ knife.name_args = [ 'my_user' ]
29
+ allow(user_mock).to receive(:username).and_return('my_user')
30
+ allow(knife.ui).to receive(:stderr).and_return(stdout)
31
+ allow(knife.ui).to receive(:stdout).and_return(stdout)
32
+ end
33
+
34
+ # delete this once OSC11 support is gone
35
+ context "when the username field is not supported by the server" do
36
+ before do
37
+ allow(knife).to receive(:run_osc_11_user_show).and_raise(SystemExit)
38
+ allow(Chef::User).to receive(:load).with('my_user').and_return(user_mock)
39
+ allow(user_mock).to receive(:username).and_return(nil)
40
+ end
41
+
42
+ it "displays the osc warning" do
43
+ expect(knife.ui).to receive(:warn).with(knife.osc_11_warning)
44
+ expect{ knife.run }.to raise_error(SystemExit)
45
+ end
46
+
47
+ it "forwards the command to knife osc_user edit" do
48
+ expect(knife).to receive(:run_osc_11_user_show)
49
+ expect{ knife.run }.to raise_error(SystemExit)
50
+ end
27
51
  end
28
52
 
29
53
  it 'loads and displays the user' do
30
- expect(Chef::User).to receive(:load).with('my_user').and_return(@user_mock)
31
- expect(@knife).to receive(:format_for_display).with(@user_mock)
32
- @knife.run
54
+ expect(Chef::User).to receive(:load).with('my_user').and_return(user_mock)
55
+ expect(knife).to receive(:format_for_display).with(user_mock)
56
+ knife.run
33
57
  end
34
58
 
35
59
  it 'prints usage and exits when a user name is not provided' do
36
- @knife.name_args = []
37
- expect(@knife).to receive(:show_usage)
38
- expect(@knife.ui).to receive(:fatal)
39
- expect { @knife.run }.to raise_error(SystemExit)
60
+ knife.name_args = []
61
+ expect(knife).to receive(:show_usage)
62
+ expect(knife.ui).to receive(:fatal)
63
+ expect { knife.run }.to raise_error(SystemExit)
40
64
  end
41
65
  end
@@ -140,7 +140,7 @@ describe Chef::Knife do
140
140
  'X-Chef-Version' => Chef::VERSION,
141
141
  "Host"=>"api.opscode.piab",
142
142
  "X-REMOTE-REQUEST-ID"=>request_id,
143
- 'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::SERVER_API_VERSION}}
143
+ 'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::DEFAULT_SERVER_API_VERSION}}
144
144
 
145
145
  let(:request_id) {"1234"}
146
146
 
@@ -399,11 +399,17 @@ describe Chef::Knife do
399
399
  it "formats 406s (non-supported API version error) nicely" do
400
400
  response = Net::HTTPNotAcceptable.new("1.1", "406", "Not Acceptable")
401
401
  response.instance_variable_set(:@read, true) # I hate you, net/http.
402
- allow(response).to receive(:body).and_return(Chef::JSONCompat.to_json(:error => "sad trombone", :min_version => "0", :max_version => "1"))
402
+
403
+ # set the header
404
+ response["x-ops-server-api-version"] = Chef::JSONCompat.to_json(:min_version => "0", :max_version => "1", :request_version => "10000000")
405
+
406
+ allow(response).to receive(:body).and_return(Chef::JSONCompat.to_json(:error => "sad trombone"))
403
407
  allow(knife).to receive(:run).and_raise(Net::HTTPServerException.new("406 Not Acceptable", response))
408
+
404
409
  knife.run_with_pretty_exceptions
405
- expect(stderr.string).to include('The version of Chef that Knife is using is not supported by the Chef server you sent this request to')
406
- expect(stderr.string).to include("This version of Chef requires a server API version of #{Chef::HTTP::Authenticator::SERVER_API_VERSION}")
410
+ expect(stderr.string).to include('The request that Knife sent was using API version 10000000')
411
+ expect(stderr.string).to include('The Chef server you sent the request to supports a min API verson of 0 and a max API version of 1')
412
+ expect(stderr.string).to include('Please either update your Chef client or server to be a compatible set')
407
413
  end
408
414
 
409
415
  it "formats 500s nicely" do
@@ -38,7 +38,7 @@ describe "LWRP" do
38
38
  end
39
39
 
40
40
  def get_lwrp(name)
41
- Chef::Resource.resource_for_node(name, Chef::Node.new)
41
+ Chef::ResourceResolver.resolve(name)
42
42
  end
43
43
 
44
44
  def get_lwrp_provider(name)
@@ -122,6 +122,23 @@ describe "LWRP" do
122
122
 
123
123
  end
124
124
 
125
+ context "When an LWRP resource in cookbook l-w-r-p is loaded" do
126
+ before do
127
+ @tmpdir = Dir.mktmpdir("lwrp_test")
128
+ resource_path = File.join(@tmpdir, "foo.rb")
129
+ IO.write(resource_path, "default_action :create")
130
+ provider_path = File.join(@tmpdir, "foo.rb")
131
+ IO.write(provider_path, <<-EOM)
132
+ action :create do
133
+ raise "hi"
134
+ end
135
+ EOM
136
+ end
137
+
138
+ it "Can find the resource at l_w_r_p_foo" do
139
+ end
140
+ end
141
+
125
142
  context "When an LWRP resource lwrp_foo is loaded" do
126
143
  before do
127
144
  @tmpdir = Dir.mktmpdir("lwrp_test")
@@ -129,7 +146,7 @@ describe "LWRP" do
129
146
  content = IO.read(File.expand_path("../../data/lwrp/resources/foo.rb", __FILE__))
130
147
  IO.write(@lwrp_path, content)
131
148
  Chef::Resource::LWRPBase.build_from_file("lwrp", @lwrp_path, nil)
132
- @original_resource = Chef::Resource.resource_for_node(:lwrp_foo, Chef::Node.new)
149
+ @original_resource = Chef::ResourceResolver.resolve(:lwrp_foo)
133
150
  end
134
151
 
135
152
  after do
@@ -144,9 +161,9 @@ describe "LWRP" do
144
161
  end
145
162
 
146
163
  it "Should load the old content, and not the new" do
147
- resource = Chef::Resource.resource_for_node(:lwrp_foo, Chef::Node.new)
164
+ resource = Chef::ResourceResolver.resolve(:lwrp_foo)
148
165
  expect(resource).to eq @original_resource
149
- expect(resource.default_action).to eq([:pass_buck])
166
+ expect(resource.default_action).to eq(:pass_buck)
150
167
  expect(Chef.method_defined?(:method_created_by_override_lwrp_foo)).to be_falsey
151
168
  end
152
169
  end
@@ -160,8 +177,8 @@ describe "LWRP" do
160
177
  end
161
178
  end
162
179
 
163
- it "should load the resource into a properly-named class and emit a warning about deprecation when accessing it" do
164
- expect { Chef::Resource::LwrpFoo }.to raise_error(Chef::Exceptions::DeprecatedFeatureError)
180
+ it "should load the resource into a properly-named class and emit a warning when it is initialized" do
181
+ expect { Chef::Resource::LwrpFoo.new('hi') }.to raise_error(Chef::Exceptions::DeprecatedFeatureError)
165
182
  end
166
183
 
167
184
  it "should be resolvable with Chef::ResourceResolver.resolve(:lwrp_foo)" do
@@ -185,7 +202,7 @@ describe "LWRP" do
185
202
  end
186
203
 
187
204
  it "should set the specified action as the default action" do
188
- expect(get_lwrp(:lwrp_foo).new("blah").action).to eq([:pass_buck])
205
+ expect(get_lwrp(:lwrp_foo).new("blah").action).to eq(:pass_buck)
189
206
  end
190
207
 
191
208
  it "should create a method for each attribute" do
@@ -211,6 +228,127 @@ describe "LWRP" do
211
228
  expect(cls.node[:penguin_name]).to eql("jackass")
212
229
  end
213
230
 
231
+ context "resource class created" do
232
+ before do
233
+ @old_treat_deprecation_warnings_as_errors = Chef::Config[:treat_deprecation_warnings_as_errors]
234
+ Chef::Config[:treat_deprecation_warnings_as_errors] = false
235
+ end
236
+ after do
237
+ Chef::Config[:treat_deprecation_warnings_as_errors] = @old_treat_deprecation_warnings_as_errors
238
+ end
239
+
240
+ it "should load the resource into a properly-named class" do
241
+ expect(Chef::Resource::LwrpFoo).to be_kind_of(Class)
242
+ expect(Chef::Resource::LwrpFoo <= Chef::Resource::LWRPBase).to be_truthy
243
+ end
244
+
245
+ it "get_lwrp(:lwrp_foo).new is a Chef::Resource::LwrpFoo" do
246
+ lwrp = get_lwrp(:lwrp_foo).new('hi')
247
+ expect(lwrp.kind_of?(Chef::Resource::LwrpFoo)).to be_truthy
248
+ expect(lwrp.is_a?(Chef::Resource::LwrpFoo)).to be_truthy
249
+ expect(get_lwrp(:lwrp_foo) === lwrp).to be_truthy
250
+ expect(Chef::Resource::LwrpFoo === lwrp).to be_truthy
251
+ end
252
+
253
+ it "Chef::Resource::LwrpFoo.new is a get_lwrp(:lwrp_foo)" do
254
+ lwrp = Chef::Resource::LwrpFoo.new('hi')
255
+ expect(lwrp.kind_of?(get_lwrp(:lwrp_foo))).to be_truthy
256
+ expect(lwrp.is_a?(get_lwrp(:lwrp_foo))).to be_truthy
257
+ expect(get_lwrp(:lwrp_foo) === lwrp).to be_truthy
258
+ expect(Chef::Resource::LwrpFoo === lwrp).to be_truthy
259
+ end
260
+
261
+ it "works even if LwrpFoo exists in the top level" do
262
+ module ::LwrpFoo
263
+ end
264
+ expect(Chef::Resource::LwrpFoo).not_to eq(::LwrpFoo)
265
+ end
266
+
267
+ context "with a subclass of get_lwrp(:lwrp_foo)" do
268
+ let(:subclass) do
269
+ Class.new(get_lwrp(:lwrp_foo))
270
+ end
271
+
272
+ it "subclass.new is a subclass" do
273
+ lwrp = subclass.new('hi')
274
+ expect(lwrp.kind_of?(subclass)).to be_truthy
275
+ expect(lwrp.is_a?(subclass)).to be_truthy
276
+ expect(subclass === lwrp).to be_truthy
277
+ expect(lwrp.class === subclass)
278
+ end
279
+ it "subclass.new is a Chef::Resource::LwrpFoo" do
280
+ lwrp = subclass.new('hi')
281
+ expect(lwrp.kind_of?(Chef::Resource::LwrpFoo)).to be_truthy
282
+ expect(lwrp.is_a?(Chef::Resource::LwrpFoo)).to be_truthy
283
+ expect(Chef::Resource::LwrpFoo === lwrp).to be_truthy
284
+ expect(lwrp.class === Chef::Resource::LwrpFoo)
285
+ end
286
+ it "subclass.new is a get_lwrp(:lwrp_foo)" do
287
+ lwrp = subclass.new('hi')
288
+ expect(lwrp.kind_of?(get_lwrp(:lwrp_foo))).to be_truthy
289
+ expect(lwrp.is_a?(get_lwrp(:lwrp_foo))).to be_truthy
290
+ expect(get_lwrp(:lwrp_foo) === lwrp).to be_truthy
291
+ expect(lwrp.class === get_lwrp(:lwrp_foo))
292
+ end
293
+ it "Chef::Resource::LwrpFoo.new is *not* a subclass" do
294
+ lwrp = Chef::Resource::LwrpFoo.new('hi')
295
+ expect(lwrp.kind_of?(subclass)).to be_falsey
296
+ expect(lwrp.is_a?(subclass)).to be_falsey
297
+ expect(subclass === lwrp.class).to be_falsey
298
+ expect(subclass === Chef::Resource::LwrpFoo).to be_falsey
299
+ end
300
+ it "get_lwrp(:lwrp_foo).new is *not* a subclass" do
301
+ lwrp = get_lwrp(:lwrp_foo).new('hi')
302
+ expect(lwrp.kind_of?(subclass)).to be_falsey
303
+ expect(lwrp.is_a?(subclass)).to be_falsey
304
+ expect(subclass === lwrp.class).to be_falsey
305
+ expect(subclass === get_lwrp(:lwrp_foo)).to be_falsey
306
+ end
307
+ end
308
+
309
+ context "with a subclass of Chef::Resource::LwrpFoo" do
310
+ let(:subclass) do
311
+ Class.new(Chef::Resource::LwrpFoo)
312
+ end
313
+
314
+ it "subclass.new is a subclass" do
315
+ lwrp = subclass.new('hi')
316
+ expect(lwrp.kind_of?(subclass)).to be_truthy
317
+ expect(lwrp.is_a?(subclass)).to be_truthy
318
+ expect(subclass === lwrp).to be_truthy
319
+ expect(lwrp.class === subclass)
320
+ end
321
+ it "subclass.new is a Chef::Resource::LwrpFoo" do
322
+ lwrp = subclass.new('hi')
323
+ expect(lwrp.kind_of?(Chef::Resource::LwrpFoo)).to be_truthy
324
+ expect(lwrp.is_a?(Chef::Resource::LwrpFoo)).to be_truthy
325
+ expect(Chef::Resource::LwrpFoo === lwrp).to be_truthy
326
+ expect(lwrp.class === Chef::Resource::LwrpFoo)
327
+ end
328
+ it "subclass.new is a get_lwrp(:lwrp_foo)" do
329
+ lwrp = subclass.new('hi')
330
+ expect(lwrp.kind_of?(get_lwrp(:lwrp_foo))).to be_truthy
331
+ expect(lwrp.is_a?(get_lwrp(:lwrp_foo))).to be_truthy
332
+ expect(get_lwrp(:lwrp_foo) === lwrp).to be_truthy
333
+ expect(lwrp.class === get_lwrp(:lwrp_foo))
334
+ end
335
+ it "Chef::Resource::LwrpFoo.new is *not* a subclass" do
336
+ lwrp = Chef::Resource::LwrpFoo.new('hi')
337
+ expect(lwrp.kind_of?(subclass)).to be_falsey
338
+ expect(lwrp.is_a?(subclass)).to be_falsey
339
+ expect(subclass === lwrp.class).to be_falsey
340
+ expect(subclass === Chef::Resource::LwrpFoo).to be_falsey
341
+ end
342
+ it "get_lwrp(:lwrp_foo).new is *not* a subclass" do
343
+ lwrp = get_lwrp(:lwrp_foo).new('hi')
344
+ expect(lwrp.kind_of?(subclass)).to be_falsey
345
+ expect(lwrp.is_a?(subclass)).to be_falsey
346
+ expect(subclass === lwrp.class).to be_falsey
347
+ expect(subclass === get_lwrp(:lwrp_foo)).to be_falsey
348
+ end
349
+ end
350
+ end
351
+
214
352
  context "resource_name" do
215
353
  let(:klass) { Class.new(Chef::Resource::LWRPBase) }
216
354
 
@@ -229,14 +367,6 @@ describe "LWRP" do
229
367
  expect(klass.resource_name).to eq(:foo)
230
368
  end
231
369
 
232
- context "when creating a new instance" do
233
- it "raises an exception if resource_name is nil" do
234
- expect {
235
- klass.new('blah')
236
- }.to raise_error(Chef::Exceptions::InvalidResourceSpecification)
237
- end
238
- end
239
-
240
370
  context "lazy default values" do
241
371
  let(:klass) do
242
372
  Class.new(Chef::Resource::LWRPBase) do
@@ -289,7 +419,7 @@ describe "LWRP" do
289
419
  end
290
420
 
291
421
  it "delegates #default_action to the parent" do
292
- expect(child.default_action).to eq([:eat])
422
+ expect(child.default_action).to eq(:eat)
293
423
  end
294
424
  end
295
425
 
@@ -306,7 +436,7 @@ describe "LWRP" do
306
436
  end
307
437
 
308
438
  it "does not delegate #default_action to the parent" do
309
- expect(child.default_action).to eq([:dont_eat])
439
+ expect(child.default_action).to eq(:dont_eat)
310
440
  end
311
441
  end
312
442
 
@@ -335,27 +465,38 @@ describe "LWRP" do
335
465
  end
336
466
 
337
467
  describe "Lightweight Chef::Provider" do
468
+
469
+ let(:node) do
470
+ Chef::Node.new.tap do |n|
471
+ n.automatic[:platform] = :ubuntu
472
+ n.automatic[:platform_version] = '8.10'
473
+ end
474
+ end
475
+
476
+ let(:events) { Chef::EventDispatch::Dispatcher.new }
477
+
478
+ let(:run_context) { Chef::RunContext.new(node, Chef::CookbookCollection.new({}), events) }
479
+
480
+ let(:runner) { Chef::Runner.new(run_context) }
481
+
482
+ let(:lwrp_cookbok_name) { "lwrp" }
483
+
338
484
  before do
339
- @node = Chef::Node.new
340
- @node.automatic[:platform] = :ubuntu
341
- @node.automatic[:platform_version] = '8.10'
342
- @events = Chef::EventDispatch::Dispatcher.new
343
- @run_context = Chef::RunContext.new(@node, Chef::CookbookCollection.new({}), @events)
344
- @runner = Chef::Runner.new(@run_context)
485
+ Chef::Provider::LWRPBase.class_eval { @loaded_lwrps = {} }
345
486
  end
346
487
 
347
488
  before(:each) do
348
489
  Dir[File.expand_path(File.expand_path("../../data/lwrp/resources/*", __FILE__))].each do |file|
349
- Chef::Resource::LWRPBase.build_from_file("lwrp", file, @run_context)
490
+ Chef::Resource::LWRPBase.build_from_file(lwrp_cookbok_name, file, run_context)
350
491
  end
351
492
 
352
493
  Dir[File.expand_path(File.expand_path("../../data/lwrp/providers/*", __FILE__))].each do |file|
353
- Chef::Provider::LWRPBase.build_from_file("lwrp", file, @run_context)
494
+ Chef::Provider::LWRPBase.build_from_file(lwrp_cookbok_name, file, run_context)
354
495
  end
355
496
  end
356
497
 
357
498
  it "should properly handle a new_resource reference" do
358
- resource = get_lwrp(:lwrp_foo).new("morpheus", @run_context)
499
+ resource = get_lwrp(:lwrp_foo).new("morpheus", run_context)
359
500
  resource.monkey("bob")
360
501
  resource.provider(get_lwrp_provider(:lwrp_monkey_name_printer))
361
502
 
@@ -363,11 +504,12 @@ describe "LWRP" do
363
504
  provider.action_twiddle_thumbs
364
505
  end
365
506
 
366
- context "resource class created" do
507
+ context "provider class created" do
367
508
  before do
368
509
  @old_treat_deprecation_warnings_as_errors = Chef::Config[:treat_deprecation_warnings_as_errors]
369
510
  Chef::Config[:treat_deprecation_warnings_as_errors] = false
370
511
  end
512
+
371
513
  after do
372
514
  Chef::Config[:treat_deprecation_warnings_as_errors] = @old_treat_deprecation_warnings_as_errors
373
515
  end
@@ -381,54 +523,86 @@ describe "LWRP" do
381
523
  expect(get_lwrp_provider(:lwrp_buck_passer).instance_methods).to include(:action_pass_buck)
382
524
  expect(get_lwrp_provider(:lwrp_thumb_twiddler).instance_methods).to include(:action_twiddle_thumbs)
383
525
  end
526
+
527
+ it "sets itself as a provider for a resource of the same name" do
528
+ found_providers = Chef::Platform::ProviderPriorityMap.instance.list_handlers(node, :lwrp_buck_passer)
529
+ # we bypass the per-file loading to get the file to load each time,
530
+ # which creates the LWRP class repeatedly. New things get prepended to
531
+ # the list of providers.
532
+ expect(found_providers.first).to eq(get_lwrp_provider(:lwrp_buck_passer))
533
+ end
534
+
535
+ context "with a cookbook with an underscore in the name" do
536
+
537
+ let(:lwrp_cookbok_name) { "l_w_r_p" }
538
+
539
+ it "sets itself as a provider for a resource of the same name" do
540
+ found_providers = Chef::Platform::ProviderPriorityMap.instance.list_handlers(node, :l_w_r_p_buck_passer)
541
+ expect(found_providers.size).to eq(1)
542
+ expect(found_providers.last).to eq(get_lwrp_provider(:l_w_r_p_buck_passer))
543
+ end
544
+ end
545
+
546
+ context "with a cookbook with a hypen in the name" do
547
+
548
+ let(:lwrp_cookbok_name) { "l-w-r-p" }
549
+
550
+ it "sets itself as a provider for a resource of the same name" do
551
+ incorrect_providers = Chef::Platform::ProviderPriorityMap.instance.list_handlers(node, :'l-w-r-p_buck_passer')
552
+ expect(incorrect_providers).to eq([])
553
+
554
+ found_providers = Chef::Platform::ProviderPriorityMap.instance.list_handlers(node, :l_w_r_p_buck_passer)
555
+ expect(found_providers.first).to eq(get_lwrp_provider(:l_w_r_p_buck_passer))
556
+ end
557
+ end
384
558
  end
385
559
 
386
560
  it "should insert resources embedded in the provider into the middle of the resource collection" do
387
- injector = get_lwrp(:lwrp_foo).new("morpheus", @run_context)
561
+ injector = get_lwrp(:lwrp_foo).new("morpheus", run_context)
388
562
  injector.action(:pass_buck)
389
563
  injector.provider(get_lwrp_provider(:lwrp_buck_passer))
390
- dummy = Chef::Resource::ZenMaster.new("keanu reeves", @run_context)
564
+ dummy = Chef::Resource::ZenMaster.new("keanu reeves", run_context)
391
565
  dummy.provider(Chef::Provider::Easy)
392
- @run_context.resource_collection.insert(injector)
393
- @run_context.resource_collection.insert(dummy)
566
+ run_context.resource_collection.insert(injector)
567
+ run_context.resource_collection.insert(dummy)
394
568
 
395
- Chef::Runner.new(@run_context).converge
569
+ Chef::Runner.new(run_context).converge
396
570
 
397
- expect(@run_context.resource_collection[0]).to eql(injector)
398
- expect(@run_context.resource_collection[1].name).to eql('prepared_thumbs')
399
- expect(@run_context.resource_collection[2].name).to eql('twiddled_thumbs')
400
- expect(@run_context.resource_collection[3]).to eql(dummy)
571
+ expect(run_context.resource_collection[0]).to eql(injector)
572
+ expect(run_context.resource_collection[1].name).to eql('prepared_thumbs')
573
+ expect(run_context.resource_collection[2].name).to eql('twiddled_thumbs')
574
+ expect(run_context.resource_collection[3]).to eql(dummy)
401
575
  end
402
576
 
403
577
  it "should insert embedded resources from multiple providers, including from the last position, properly into the resource collection" do
404
- injector = get_lwrp(:lwrp_foo).new("morpheus", @run_context)
578
+ injector = get_lwrp(:lwrp_foo).new("morpheus", run_context)
405
579
  injector.action(:pass_buck)
406
580
  injector.provider(get_lwrp_provider(:lwrp_buck_passer))
407
581
 
408
- injector2 = get_lwrp(:lwrp_bar).new("tank", @run_context)
582
+ injector2 = get_lwrp(:lwrp_bar).new("tank", run_context)
409
583
  injector2.action(:pass_buck)
410
584
  injector2.provider(get_lwrp_provider(:lwrp_buck_passer_2))
411
585
 
412
- dummy = Chef::Resource::ZenMaster.new("keanu reeves", @run_context)
586
+ dummy = Chef::Resource::ZenMaster.new("keanu reeves", run_context)
413
587
  dummy.provider(Chef::Provider::Easy)
414
588
 
415
- @run_context.resource_collection.insert(injector)
416
- @run_context.resource_collection.insert(dummy)
417
- @run_context.resource_collection.insert(injector2)
589
+ run_context.resource_collection.insert(injector)
590
+ run_context.resource_collection.insert(dummy)
591
+ run_context.resource_collection.insert(injector2)
418
592
 
419
- Chef::Runner.new(@run_context).converge
593
+ Chef::Runner.new(run_context).converge
420
594
 
421
- expect(@run_context.resource_collection[0]).to eql(injector)
422
- expect(@run_context.resource_collection[1].name).to eql('prepared_thumbs')
423
- expect(@run_context.resource_collection[2].name).to eql('twiddled_thumbs')
424
- expect(@run_context.resource_collection[3]).to eql(dummy)
425
- expect(@run_context.resource_collection[4]).to eql(injector2)
426
- expect(@run_context.resource_collection[5].name).to eql('prepared_eyes')
427
- expect(@run_context.resource_collection[6].name).to eql('dried_paint_watched')
595
+ expect(run_context.resource_collection[0]).to eql(injector)
596
+ expect(run_context.resource_collection[1].name).to eql('prepared_thumbs')
597
+ expect(run_context.resource_collection[2].name).to eql('twiddled_thumbs')
598
+ expect(run_context.resource_collection[3]).to eql(dummy)
599
+ expect(run_context.resource_collection[4]).to eql(injector2)
600
+ expect(run_context.resource_collection[5].name).to eql('prepared_eyes')
601
+ expect(run_context.resource_collection[6].name).to eql('dried_paint_watched')
428
602
  end
429
603
 
430
604
  it "should properly handle a new_resource reference" do
431
- resource = get_lwrp(:lwrp_foo).new("morpheus", @run_context)
605
+ resource = get_lwrp(:lwrp_foo).new("morpheus", run_context)
432
606
  resource.monkey("bob")
433
607
  resource.provider(get_lwrp_provider(:lwrp_monkey_name_printer))
434
608
 
@@ -439,7 +613,7 @@ describe "LWRP" do
439
613
  end
440
614
 
441
615
  it "should properly handle an embedded Resource accessing the enclosing Provider's scope" do
442
- resource = get_lwrp(:lwrp_foo).new("morpheus", @run_context)
616
+ resource = get_lwrp(:lwrp_foo).new("morpheus", run_context)
443
617
  resource.monkey("bob")
444
618
  resource.provider(get_lwrp_provider(:lwrp_embedded_resource_accesses_providers_scope))
445
619
 
@@ -458,7 +632,7 @@ describe "LWRP" do
458
632
  # Side effect of lwrp_inline_compiler provider for testing notifications.
459
633
  $interior_ruby_block_2 = nil
460
634
  # resource type doesn't matter, so make an existing resource type work with provider.
461
- @resource = get_lwrp(:lwrp_foo).new("morpheus", @run_context)
635
+ @resource = get_lwrp(:lwrp_foo).new("morpheus", run_context)
462
636
  @resource.allowed_actions << :test
463
637
  @resource.action(:test)
464
638
  @resource.provider(get_lwrp_provider(:lwrp_inline_compiler))
@@ -466,7 +640,7 @@ describe "LWRP" do
466
640
 
467
641
  it "does not add interior resources to the exterior resource collection" do
468
642
  @resource.run_action(:test)
469
- expect(@run_context.resource_collection).to be_empty
643
+ expect(run_context.resource_collection).to be_empty
470
644
  end
471
645
 
472
646
  context "when interior resources are updated" do