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
@@ -121,7 +121,7 @@ describe Chef::Recipe do
121
121
 
122
122
  it "locate resource for particular platform" do
123
123
  ShaunTheSheep = Class.new(Chef::Resource)
124
- ShaunTheSheep.provides :laughter, :on_platforms => ["television"]
124
+ ShaunTheSheep.provides :laughter, :platform => ["television"]
125
125
  node.automatic[:platform] = "television"
126
126
  node.automatic[:platform_version] = "123"
127
127
  res = recipe.laughter "timmy"
@@ -141,9 +141,7 @@ describe Chef::Recipe do
141
141
  before do
142
142
  node.automatic[:platform] = "nbc_sports"
143
143
  Sounders = Class.new(Chef::Resource)
144
- Sounders.provides :football, platform: "nbc_sports"
145
144
  TottenhamHotspur = Class.new(Chef::Resource)
146
- TottenhamHotspur.provides :football, platform: "nbc_sports"
147
145
  end
148
146
 
149
147
  after do
@@ -151,16 +149,12 @@ describe Chef::Recipe do
151
149
  Object.send(:remove_const, :TottenhamHotspur)
152
150
  end
153
151
 
154
- it "warns if resolution of the two resources is ambiguous" do
155
- expect(Chef::Log).to receive(:warn).at_least(:once).with(/Ambiguous resource precedence/)
156
- res1 = recipe.football "club world cup"
157
- expect(res1.name).to eql("club world cup")
158
- # the class of res1 is not defined.
159
- end
160
-
161
- it "selects one if it is given priority" do
152
+ it "selects one if it is the last declared" do
162
153
  expect(Chef::Log).not_to receive(:warn)
163
- Chef::Platform::ResourcePriorityMap.instance.send(:priority, :football, TottenhamHotspur, platform: "nbc_sports")
154
+
155
+ Sounders.provides :football, platform: "nbc_sports"
156
+ TottenhamHotspur.provides :football, platform: "nbc_sports"
157
+
164
158
  res1 = recipe.football "club world cup"
165
159
  expect(res1.name).to eql("club world cup")
166
160
  expect(res1).to be_a_kind_of(TottenhamHotspur)
@@ -168,7 +162,10 @@ describe Chef::Recipe do
168
162
 
169
163
  it "selects the other one if it is given priority" do
170
164
  expect(Chef::Log).not_to receive(:warn)
171
- Chef::Platform::ResourcePriorityMap.instance.send(:priority, :football, Sounders, platform: "nbc_sports")
165
+
166
+ TottenhamHotspur.provides :football, platform: "nbc_sports"
167
+ Sounders.provides :football, platform: "nbc_sports"
168
+
172
169
  res1 = recipe.football "club world cup"
173
170
  expect(res1.name).to eql("club world cup")
174
171
  expect(res1).to be_a_kind_of(Sounders)
@@ -408,7 +405,7 @@ describe Chef::Recipe do
408
405
  end
409
406
 
410
407
  it "does not copy the action from the first resource" do
411
- expect(original_resource.action).to eq([:score])
408
+ expect(original_resource.action).to eq(:score)
412
409
  expect(duplicated_resource.action).to eq(:nothing)
413
410
  end
414
411
 
@@ -504,7 +501,7 @@ describe Chef::Recipe do
504
501
  recipe.from_file(File.join(CHEF_SPEC_DATA, "recipes", "test.rb"))
505
502
  res = recipe.resources(:file => "/etc/nsswitch.conf")
506
503
  expect(res.name).to eql("/etc/nsswitch.conf")
507
- expect(res.action).to eql([:create])
504
+ expect(res.action).to eql(:create)
508
505
  expect(res.owner).to eql("root")
509
506
  expect(res.group).to eql("root")
510
507
  expect(res.mode).to eql(0644)
@@ -577,6 +574,36 @@ describe Chef::Recipe do
577
574
  expect(cookbook_collection[:openldap]).not_to receive(:load_recipe).with("default", run_context)
578
575
  openldap_recipe.include_recipe "::default"
579
576
  end
577
+
578
+ it "will not load a recipe twice when called first from an LWRP provider" do
579
+ openldap_recipe = Chef::Recipe.new("openldap", "test", run_context)
580
+ expect(node).to receive(:loaded_recipe).with(:openldap, "default").exactly(:once)
581
+ allow(run_context).to receive(:unreachable_cookbook?).with(:openldap).and_return(false)
582
+ expect(cookbook_collection[:openldap]).to receive(:load_recipe).with("default", run_context)
583
+ openldap_recipe.include_recipe "::default"
584
+ expect(cookbook_collection[:openldap]).not_to receive(:load_recipe).with("default", run_context)
585
+ openldap_recipe.openldap_includer("do it").run_action(:run)
586
+ end
587
+
588
+ it "will not load a recipe twice when called last from an LWRP provider" do
589
+ openldap_recipe = Chef::Recipe.new("openldap", "test", run_context)
590
+ expect(node).to receive(:loaded_recipe).with(:openldap, "default").exactly(:once)
591
+ allow(run_context).to receive(:unreachable_cookbook?).with(:openldap).and_return(false)
592
+ expect(cookbook_collection[:openldap]).to receive(:load_recipe).with("default", run_context)
593
+ openldap_recipe.openldap_includer("do it").run_action(:run)
594
+ expect(cookbook_collection[:openldap]).not_to receive(:load_recipe).with("default", run_context)
595
+ openldap_recipe.include_recipe "::default"
596
+ end
597
+
598
+ it "will not load a recipe twice when called both times from an LWRP provider" do
599
+ openldap_recipe = Chef::Recipe.new("openldap", "test", run_context)
600
+ expect(node).to receive(:loaded_recipe).with(:openldap, "default").exactly(:once)
601
+ allow(run_context).to receive(:unreachable_cookbook?).with(:openldap).and_return(false)
602
+ expect(cookbook_collection[:openldap]).to receive(:load_recipe).with("default", run_context)
603
+ openldap_recipe.openldap_includer("do it").run_action(:run)
604
+ expect(cookbook_collection[:openldap]).not_to receive(:load_recipe).with("default", run_context)
605
+ openldap_recipe.openldap_includer("do it").run_action(:run)
606
+ end
580
607
  end
581
608
 
582
609
  describe "tags" do
@@ -37,7 +37,7 @@ describe Chef::Resource::Breakpoint do
37
37
  end
38
38
 
39
39
  it "defaults to the break action" do
40
- expect(@breakpoint.action).to eq("break")
40
+ expect(@breakpoint.action).to eq(:break)
41
41
  end
42
42
 
43
43
  it "names itself after the line number of the file where it's created" do
@@ -35,7 +35,7 @@ describe Chef::Resource::ErlCall do
35
35
  end
36
36
 
37
37
  it "should have a default action of run" do
38
- expect(@resource.action).to eql("run")
38
+ expect(@resource.action).to eql(:run)
39
39
  end
40
40
 
41
41
  it "should accept run as an action" do
@@ -29,7 +29,7 @@ describe Chef::Resource::File do
29
29
  end
30
30
 
31
31
  it "should have a default action of 'create'" do
32
- expect(@resource.action).to eql("create")
32
+ expect(@resource.action).to eql(:create)
33
33
  end
34
34
 
35
35
  it "should have a default content of nil" do
@@ -47,21 +47,23 @@ describe Chef::Resource::Ifconfig do
47
47
  end
48
48
  end
49
49
 
50
- shared_examples "being a platform using the default ifconfig provider" do |platform, version|
50
+ shared_examples "being a platform based on an old Debian" do |platform, version|
51
51
  before do
52
+ @node.automatic_attrs[:os] = 'linux'
53
+ @node.automatic_attrs[:platform_family] = 'debian'
52
54
  @node.automatic_attrs[:platform] = platform
53
55
  @node.automatic_attrs[:platform_version] = version
54
56
  end
55
57
 
56
58
  it "should use an ordinary Provider::Ifconfig as a provider for #{platform} #{version}" do
57
- expect(@resource.provider_for_action(:add)).to be_a_kind_of(Chef::Provider::Ifconfig)
58
- expect(@resource.provider_for_action(:add)).not_to be_a_kind_of(Chef::Provider::Ifconfig::Debian)
59
- expect(@resource.provider_for_action(:add)).not_to be_a_kind_of(Chef::Provider::Ifconfig::Redhat)
59
+ expect(@resource.provider_for_action(:add).class).to eq(Chef::Provider::Ifconfig)
60
60
  end
61
61
  end
62
62
 
63
63
  shared_examples "being a platform based on RedHat" do |platform, version|
64
64
  before do
65
+ @node.automatic_attrs[:os] = 'linux'
66
+ @node.automatic_attrs[:platform_family] = 'rhel'
65
67
  @node.automatic_attrs[:platform] = platform
66
68
  @node.automatic_attrs[:platform_version] = version
67
69
  end
@@ -73,6 +75,8 @@ describe Chef::Resource::Ifconfig do
73
75
 
74
76
  shared_examples "being a platform based on a recent Debian" do |platform, version|
75
77
  before do
78
+ @node.automatic_attrs[:os] = 'linux'
79
+ @node.automatic_attrs[:platform_family] = 'debian'
76
80
  @node.automatic_attrs[:platform] = platform
77
81
  @node.automatic_attrs[:platform_version] = version
78
82
  end
@@ -87,7 +91,7 @@ describe Chef::Resource::Ifconfig do
87
91
  end
88
92
 
89
93
  describe "when it is an old Debian platform" do
90
- it_should_behave_like "being a platform using the default ifconfig provider", "debian", "6.0"
94
+ it_should_behave_like "being a platform based on an old Debian", "debian", "6.0"
91
95
  end
92
96
 
93
97
  describe "when it is a new Debian platform" do
@@ -95,7 +99,7 @@ describe Chef::Resource::Ifconfig do
95
99
  end
96
100
 
97
101
  describe "when it is an old Ubuntu platform" do
98
- it_should_behave_like "being a platform using the default ifconfig provider", "ubuntu", "11.04"
102
+ it_should_behave_like "being a platform based on an old Debian", "ubuntu", "11.04"
99
103
  end
100
104
 
101
105
  describe "when it is a new Ubuntu platform" do
@@ -60,6 +60,11 @@ describe Chef::Resource::RemoteFile do
60
60
  expect(@resource.source).to eql([ "\\\\fakey\\fakerton\\fake.txt" ])
61
61
  end
62
62
 
63
+ it 'should accept file URIs with spaces' do
64
+ @resource.source("file:///C:/foo bar")
65
+ expect(@resource.source).to eql(["file:///C:/foo bar"])
66
+ end
67
+
63
68
  it "should accept a delayed evalutator (string) for the remote file source" do
64
69
  @resource.source Chef::DelayedEvaluator.new {"http://opscode.com/"}
65
70
  expect(@resource.source).to eql([ "http://opscode.com/" ])
@@ -35,7 +35,7 @@ describe Chef::Resource::Route do
35
35
  end
36
36
 
37
37
  it "should have a default action of 'add'" do
38
- expect(@resource.action).to eql([:add])
38
+ expect(@resource.action).to eql(:add)
39
39
  end
40
40
 
41
41
  it "should accept add or delete for action" do
@@ -31,7 +31,7 @@ describe Chef::Resource::RubyBlock do
31
31
  end
32
32
 
33
33
  it "should have a default action of 'create'" do
34
- expect(@resource.action).to eql("run")
34
+ expect(@resource.action).to eql(:run)
35
35
  end
36
36
 
37
37
  it "should have a resource name of :ruby_block" do
@@ -46,7 +46,7 @@ describe Chef::Resource::RubyBlock do
46
46
 
47
47
  it "allows the action to be 'create'" do
48
48
  @resource.action :create
49
- expect(@resource.action).to eq([:create])
49
+ expect(@resource.action).to eq(:create)
50
50
  end
51
51
 
52
52
  describe "when it has been initialized with block code" do
@@ -98,7 +98,7 @@ describe Chef::Resource::Template do
98
98
 
99
99
  context "on windows", :windows_only do
100
100
  # according to Chef::Resource::File, windows state attributes are rights + deny_rights
101
- pending "it describes its state"
101
+ skip "it describes its state"
102
102
  end
103
103
 
104
104
  it "returns the file path as its identity" do
@@ -23,11 +23,10 @@ describe Chef::Resource::TimestampedDeploy, "initialize" do
23
23
  static_provider_resolution(
24
24
  resource: Chef::Resource::TimestampedDeploy,
25
25
  provider: Chef::Provider::Deploy::Timestamped,
26
- name: :deploy,
26
+ name: :timestamped_deploy,
27
27
  action: :deploy,
28
28
  os: 'linux',
29
29
  platform_family: 'rhel',
30
30
  )
31
31
 
32
32
  end
33
-
@@ -44,6 +44,6 @@ describe Chef::Resource::WindowsService, "initialize" do
44
44
 
45
45
  it "allows the action to be 'configure_startup'" do
46
46
  resource.action :configure_startup
47
- expect(resource.action).to eq([:configure_startup])
47
+ expect(resource.action).to eq(:configure_startup)
48
48
  end
49
49
  end
@@ -21,10 +21,6 @@
21
21
 
22
22
  require 'spec_helper'
23
23
 
24
- class ResourceTestHarness < Chef::Resource
25
- provider_base Chef::Provider::Package
26
- end
27
-
28
24
  describe Chef::Resource do
29
25
  before(:each) do
30
26
  @cookbook_repo_path = File.join(CHEF_SPEC_DATA, 'cookbooks')
@@ -35,6 +31,18 @@ describe Chef::Resource do
35
31
  @resource = Chef::Resource.new("funk", @run_context)
36
32
  end
37
33
 
34
+ it "should mixin shell_out" do
35
+ expect(@resource.respond_to?(:shell_out)).to be true
36
+ end
37
+
38
+ it "should mixin shell_out!" do
39
+ expect(@resource.respond_to?(:shell_out!)).to be true
40
+ end
41
+
42
+ it "should mixin shell_out_with_systems_locale" do
43
+ expect(@resource.respond_to?(:shell_out_with_systems_locale)).to be true
44
+ end
45
+
38
46
  describe "when inherited" do
39
47
 
40
48
  it "adds an entry to a list of subclasses" do
@@ -324,6 +332,71 @@ describe Chef::Resource do
324
332
  end
325
333
  end
326
334
 
335
+ describe "self.resource_name" do
336
+ context "When resource_name is not set" do
337
+ it "and there are no provides lines, resource_name is nil" do
338
+ c = Class.new(Chef::Resource) do
339
+ end
340
+
341
+ r = c.new('hi')
342
+ r.declared_type = :d
343
+ expect(c.resource_name).to be_nil
344
+ expect(r.resource_name).to be_nil
345
+ expect(r.declared_type).to eq :d
346
+ end
347
+ it "and there are no provides lines, @resource_name is used" do
348
+ c = Class.new(Chef::Resource) do
349
+ def initialize(*args, &block)
350
+ @resource_name = :blah
351
+ super
352
+ end
353
+ end
354
+
355
+ r = c.new('hi')
356
+ r.declared_type = :d
357
+ expect(c.resource_name).to be_nil
358
+ expect(r.resource_name).to eq :blah
359
+ expect(r.declared_type).to eq :d
360
+ end
361
+ end
362
+
363
+ it "resource_name without provides is honored" do
364
+ c = Class.new(Chef::Resource) do
365
+ resource_name 'blah'
366
+ end
367
+
368
+ r = c.new('hi')
369
+ r.declared_type = :d
370
+ expect(c.resource_name).to eq :blah
371
+ expect(r.resource_name).to eq :blah
372
+ expect(r.declared_type).to eq :d
373
+ end
374
+ it "setting class.resource_name with 'resource_name = blah' overrides declared_type" do
375
+ c = Class.new(Chef::Resource) do
376
+ provides :self_resource_name_test_2
377
+ end
378
+ c.resource_name = :blah
379
+
380
+ r = c.new('hi')
381
+ r.declared_type = :d
382
+ expect(c.resource_name).to eq :blah
383
+ expect(r.resource_name).to eq :blah
384
+ expect(r.declared_type).to eq :d
385
+ end
386
+ it "setting class.resource_name with 'resource_name blah' overrides declared_type" do
387
+ c = Class.new(Chef::Resource) do
388
+ resource_name :blah
389
+ provides :self_resource_name_test_3
390
+ end
391
+
392
+ r = c.new('hi')
393
+ r.declared_type = :d
394
+ expect(c.resource_name).to eq :blah
395
+ expect(r.resource_name).to eq :blah
396
+ expect(r.declared_type).to eq :d
397
+ end
398
+ end
399
+
327
400
  describe "is" do
328
401
  it "should return the arguments passed with 'is'" do
329
402
  zm = Chef::Resource::ZenMaster.new("coffee")
@@ -447,8 +520,21 @@ describe Chef::Resource do
447
520
  expect(Chef::Resource.provider_base).to eq(Chef::Provider)
448
521
  end
449
522
 
450
- it "allows the base provider to be overriden by a " do
451
- expect(ResourceTestHarness.provider_base).to eq(Chef::Provider::Package)
523
+ it "allows the base provider to be overridden" do
524
+ Chef::Config.treat_deprecation_warnings_as_errors(false)
525
+ class OverrideProviderBaseTest < Chef::Resource
526
+ provider_base Chef::Provider::Package
527
+ end
528
+
529
+ expect(OverrideProviderBaseTest.provider_base).to eq(Chef::Provider::Package)
530
+ end
531
+
532
+ it "warns when setting provider_base" do
533
+ expect {
534
+ class OverrideProviderBaseTest2 < Chef::Resource
535
+ provider_base Chef::Provider::Package
536
+ end
537
+ }.to raise_error(Chef::Exceptions::DeprecatedFeatureError)
452
538
  end
453
539
 
454
540
  end
@@ -709,22 +795,22 @@ describe Chef::Resource do
709
795
  end
710
796
 
711
797
  it 'adds mappings for a single platform' do
712
- expect(Chef::Resource::Klz.node_map).to receive(:set).with(
713
- :dinobot, true, { platform: ['autobots'] }
798
+ expect(Chef).to receive(:set_resource_priority_array).with(
799
+ :dinobot, Chef::Resource::Klz, { platform: ['autobots'] }
714
800
  )
715
801
  klz.provides :dinobot, platform: ['autobots']
716
802
  end
717
803
 
718
804
  it 'adds mappings for multiple platforms' do
719
- expect(Chef::Resource::Klz.node_map).to receive(:set).with(
720
- :energy, true, { platform: ['autobots', 'decepticons']}
805
+ expect(Chef).to receive(:set_resource_priority_array).with(
806
+ :energy, Chef::Resource::Klz, { platform: ['autobots', 'decepticons']}
721
807
  )
722
808
  klz.provides :energy, platform: ['autobots', 'decepticons']
723
809
  end
724
810
 
725
811
  it 'adds mappings for all platforms' do
726
- expect(Chef::Resource::Klz.node_map).to receive(:set).with(
727
- :tape_deck, true, {}
812
+ expect(Chef).to receive(:set_resource_priority_array).with(
813
+ :tape_deck, Chef::Resource::Klz, {}
728
814
  )
729
815
  klz.provides :tape_deck
730
816
  end
@@ -764,7 +850,7 @@ describe Chef::Resource do
764
850
  @node.name("bumblebee")
765
851
  @node.automatic[:platform] = "autobots"
766
852
  @node.automatic[:platform_version] = "6.1"
767
- klz2.provides :dinobot, :on_platforms => ['autobots']
853
+ klz2.provides :dinobot, :platform => ['autobots']
768
854
  Object.const_set('Grimlock', klz2)
769
855
  klz2.provides :grimlock
770
856
  end
@@ -69,8 +69,8 @@ describe Chef::REST do
69
69
  rest
70
70
  end
71
71
 
72
- let(:standard_read_headers) {{"Accept"=>"application/json", "Accept"=>"application/json", "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3", "X-REMOTE-REQUEST-ID"=>request_id, 'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::SERVER_API_VERSION}}
73
- let(:standard_write_headers) {{"Accept"=>"application/json", "Content-Type"=>"application/json", "Accept"=>"application/json", "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3", "X-REMOTE-REQUEST-ID"=>request_id, 'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::SERVER_API_VERSION}}
72
+ let(:standard_read_headers) {{"Accept"=>"application/json", "Accept"=>"application/json", "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3", "X-REMOTE-REQUEST-ID"=>request_id, 'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::DEFAULT_SERVER_API_VERSION}}
73
+ let(:standard_write_headers) {{"Accept"=>"application/json", "Content-Type"=>"application/json", "Accept"=>"application/json", "Accept-Encoding"=>"gzip;q=1.0,deflate;q=0.6,identity;q=0.3", "X-REMOTE-REQUEST-ID"=>request_id, 'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::DEFAULT_SERVER_API_VERSION}}
74
74
 
75
75
  before(:each) do
76
76
  Chef::Log.init(log_stringio)
@@ -292,7 +292,7 @@ describe Chef::REST do
292
292
  'Accept-Encoding' => Chef::REST::RESTRequest::ENCODING_GZIP_DEFLATE,
293
293
  'Host' => host_header,
294
294
  'X-REMOTE-REQUEST-ID' => request_id,
295
- 'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::SERVER_API_VERSION
295
+ 'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::DEFAULT_SERVER_API_VERSION
296
296
  }
297
297
  end
298
298
 
@@ -575,7 +575,7 @@ describe Chef::REST do
575
575
  'Accept-Encoding' => Chef::REST::RESTRequest::ENCODING_GZIP_DEFLATE,
576
576
  'Host' => host_header,
577
577
  'X-REMOTE-REQUEST-ID'=> request_id,
578
- 'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::SERVER_API_VERSION
578
+ 'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::DEFAULT_SERVER_API_VERSION
579
579
  }
580
580
  expect(Net::HTTP::Get).to receive(:new).with("/?foo=bar", expected_headers).and_return(request_mock)
581
581
  rest.streaming_request(url, {})
@@ -587,7 +587,7 @@ describe Chef::REST do
587
587
  'Accept-Encoding' => Chef::REST::RESTRequest::ENCODING_GZIP_DEFLATE,
588
588
  'Host' => host_header,
589
589
  'X-REMOTE-REQUEST-ID'=> request_id,
590
- 'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::SERVER_API_VERSION
590
+ 'X-Ops-Server-API-Version' => Chef::HTTP::Authenticator::DEFAULT_SERVER_API_VERSION
591
591
  }
592
592
  expect(Net::HTTP::Get).to receive(:new).with("/?foo=bar", expected_headers).and_return(request_mock)
593
593
  rest.streaming_request(url, {})