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
@@ -6,13 +6,8 @@ describe "Recipe DSL methods" do
6
6
  context "With resource class providing 'provider_thingy'" do
7
7
  before :context do
8
8
  class Chef::Resource::ProviderThingy < Chef::Resource
9
- def initialize(*args, &block)
10
- super
11
- @action = :create
12
- @allowed_actions = [ :create ]
13
- @resource_name = 'provider_thingy'
14
- end
15
- provides :provider_thingy
9
+ resource_name :provider_thingy
10
+ default_action :create
16
11
  def to_s
17
12
  "provider_thingy resource class"
18
13
  end
@@ -3,17 +3,26 @@ require 'support/shared/integration/integration_helper'
3
3
  describe "Recipe DSL methods" do
4
4
  include IntegrationSupport
5
5
 
6
+ module Namer
7
+ extend self
8
+ attr_accessor :current_index
9
+ end
10
+
11
+ before(:all) { Namer.current_index = 1 }
12
+ before { Namer.current_index += 1 }
13
+
6
14
  context "With resource 'base_thingy' declared as BaseThingy" do
7
15
  before(:context) {
8
16
 
9
17
  class BaseThingy < Chef::Resource
10
18
  def initialize(*args, &block)
11
19
  super
12
- @resource_name = 'base_thingy'
13
20
  @allowed_actions = [ :create ]
14
21
  @action = :create
15
22
  end
16
23
 
24
+ resource_name 'base_thingy'
25
+
17
26
  class<<self
18
27
  attr_accessor :created_resource
19
28
  attr_accessor :created_provider
@@ -54,7 +63,6 @@ describe "Recipe DSL methods" do
54
63
  class Chef::Resource::BackcompatThingy < Chef::Resource
55
64
  def initialize(*args, &block)
56
65
  super
57
- @resource_name = 'backcompat_thingy'
58
66
  @allowed_actions = [ :create ]
59
67
  @action = :create
60
68
  end
@@ -74,16 +82,16 @@ describe "Recipe DSL methods" do
74
82
  recipe = converge {
75
83
  backcompat_thingy 'blah' do; end
76
84
  }
77
- expect(recipe.logged_warnings).to match(/Class Chef::Resource::BackcompatThingy does not declare 'provides :backcompat_thingy'/i)
78
85
  expect(BaseThingy.created_resource).to eq Chef::Resource::BackcompatThingy
79
86
  expect(BaseThingy.created_provider).to eq Chef::Provider::BackcompatThingy
80
87
  end
81
88
 
82
- context "And another resource 'backcompat_thingy' in BackcompatThingy with 'provides'" do
89
+ context "and another resource 'backcompat_thingy' in BackcompatThingy with 'provides'" do
83
90
  before(:context) {
84
91
 
85
92
  class RecipeDSLSpecNamespace::BackcompatThingy < BaseThingy
86
93
  provides :backcompat_thingy
94
+ resource_name :backcompat_thingy
87
95
  end
88
96
 
89
97
  }
@@ -98,27 +106,429 @@ describe "Recipe DSL methods" do
98
106
  end
99
107
  end
100
108
 
101
- context "With a resource named RecipeDSLSpecNamespace::Bar::Thingy" do
109
+ context "With a resource named RecipeDSLSpecNamespace::Bar::BarThingy" do
110
+ before(:context) {
111
+
112
+ class RecipeDSLSpecNamespace::Bar::BarThingy < BaseThingy
113
+ end
114
+
115
+ }
116
+
117
+ it "bar_thingy works" do
118
+ recipe = converge {
119
+ bar_thingy 'blah' do; end
120
+ }
121
+ expect(recipe.logged_warnings).to eq ''
122
+ expect(BaseThingy.created_resource).to eq(RecipeDSLSpecNamespace::Bar::BarThingy)
123
+ end
124
+ end
125
+
126
+ context "With a resource named NoNameThingy with resource_name nil" do
102
127
  before(:context) {
103
128
 
104
- class RecipeDSLSpecNamespace::Bar::Thingy < BaseThingy; end
129
+ class NoNameThingy < BaseThingy
130
+ resource_name nil
131
+ end
105
132
 
106
133
  }
107
134
 
108
- it "thingy does not work" do
135
+ it "no_name_thingy does not work" do
109
136
  expect_converge {
110
137
  thingy 'blah' do; end
111
138
  }.to raise_error(NoMethodError)
112
139
  end
113
140
  end
141
+
142
+ context "With a resource named AnotherNoNameThingy with resource_name :another_thingy_name" do
143
+ before(:context) {
144
+
145
+ class AnotherNoNameThingy < BaseThingy
146
+ resource_name :another_thingy_name
147
+ end
148
+
149
+ }
150
+
151
+ it "another_no_name_thingy does not work" do
152
+ expect_converge {
153
+ another_no_name_thingy 'blah' do; end
154
+ }.to raise_error(NoMethodError)
155
+ end
156
+
157
+ it "another_thingy_name works" do
158
+ recipe = converge {
159
+ another_thingy_name 'blah' do; end
160
+ }
161
+ expect(recipe.logged_warnings).to eq ''
162
+ expect(BaseThingy.created_resource).to eq(AnotherNoNameThingy)
163
+ end
164
+ end
165
+
166
+ context "With a resource named AnotherNoNameThingy2 with resource_name :another_thingy_name2; resource_name :another_thingy_name3" do
167
+ before(:context) {
168
+
169
+ class AnotherNoNameThingy2 < BaseThingy
170
+ resource_name :another_thingy_name2
171
+ resource_name :another_thingy_name3
172
+ end
173
+
174
+ }
175
+
176
+ it "another_no_name_thingy does not work" do
177
+ expect_converge {
178
+ another_no_name_thingy2 'blah' do; end
179
+ }.to raise_error(NoMethodError)
180
+ end
181
+
182
+ it "another_thingy_name2 does not work" do
183
+ expect_converge {
184
+ another_thingy_name2 'blah' do; end
185
+ }.to raise_error(NoMethodError)
186
+ end
187
+
188
+ it "yet_another_thingy_name3 works" do
189
+ recipe = converge {
190
+ another_thingy_name3 'blah' do; end
191
+ }
192
+ expect(recipe.logged_warnings).to eq ''
193
+ expect(BaseThingy.created_resource).to eq(AnotherNoNameThingy2)
194
+ end
195
+ end
196
+
197
+ context "provides overriding resource_name" do
198
+ context "With a resource named AnotherNoNameThingy3 with provides :another_no_name_thingy3, os: 'blarghle'" do
199
+ before(:context) {
200
+
201
+ class AnotherNoNameThingy3 < BaseThingy
202
+ provides :another_no_name_thingy3, os: 'blarghle'
203
+ end
204
+
205
+ }
206
+
207
+ it "and os = linux, another_no_name_thingy3 does not work" do
208
+ expect_converge {
209
+ # TODO this is an ugly way to test, make Cheffish expose node attrs
210
+ run_context.node.automatic[:os] = 'linux'
211
+ another_no_name_thingy3 'blah' do; end
212
+ }.to raise_error(Chef::Exceptions::NoSuchResourceType)
213
+ end
214
+
215
+ it "and os = blarghle, another_no_name_thingy3 works" do
216
+ recipe = converge {
217
+ # TODO this is an ugly way to test, make Cheffish expose node attrs
218
+ run_context.node.automatic[:os] = 'blarghle'
219
+ another_no_name_thingy3 'blah' do; end
220
+ }
221
+ expect(recipe.logged_warnings).to eq ''
222
+ expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy3)
223
+ end
224
+ end
225
+
226
+ context "With a resource named AnotherNoNameThingy4 with two provides" do
227
+ before(:context) {
228
+
229
+ class AnotherNoNameThingy4 < BaseThingy
230
+ provides :another_no_name_thingy4, os: 'blarghle'
231
+ provides :another_no_name_thingy4, platform_family: 'foo'
232
+ end
233
+
234
+ }
235
+
236
+ it "and os = linux, another_no_name_thingy4 does not work" do
237
+ expect_converge {
238
+ # TODO this is an ugly way to test, make Cheffish expose node attrs
239
+ run_context.node.automatic[:os] = 'linux'
240
+ another_no_name_thingy4 'blah' do; end
241
+ }.to raise_error(Chef::Exceptions::NoSuchResourceType)
242
+ end
243
+
244
+ it "and os = blarghle, another_no_name_thingy4 works" do
245
+ recipe = converge {
246
+ # TODO this is an ugly way to test, make Cheffish expose node attrs
247
+ run_context.node.automatic[:os] = 'blarghle'
248
+ another_no_name_thingy4 'blah' do; end
249
+ }
250
+ expect(recipe.logged_warnings).to eq ''
251
+ expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy4)
252
+ end
253
+
254
+ it "and platform_family = foo, another_no_name_thingy4 works" do
255
+ recipe = converge {
256
+ # TODO this is an ugly way to test, make Cheffish expose node attrs
257
+ run_context.node.automatic[:platform_family] = 'foo'
258
+ another_no_name_thingy4 'blah' do; end
259
+ }
260
+ expect(recipe.logged_warnings).to eq ''
261
+ expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy4)
262
+ end
263
+ end
264
+
265
+ context "With a resource named AnotherNoNameThingy5, a different resource_name, and a provides with the original resource_name" do
266
+ before(:context) {
267
+
268
+ class AnotherNoNameThingy5 < BaseThingy
269
+ resource_name :another_thingy_name_for_another_no_name_thingy5
270
+ provides :another_no_name_thingy5, os: 'blarghle'
271
+ end
272
+
273
+ }
274
+
275
+ it "and os = linux, another_no_name_thingy5 does not work" do
276
+ expect_converge {
277
+ # this is an ugly way to test, make Cheffish expose node attrs
278
+ run_context.node.automatic[:os] = 'linux'
279
+ another_no_name_thingy5 'blah' do; end
280
+ }.to raise_error(Chef::Exceptions::NoSuchResourceType)
281
+ end
282
+
283
+ it "and os = blarghle, another_no_name_thingy5 works" do
284
+ recipe = converge {
285
+ # this is an ugly way to test, make Cheffish expose node attrs
286
+ run_context.node.automatic[:os] = 'blarghle'
287
+ another_no_name_thingy5 'blah' do; end
288
+ }
289
+ expect(recipe.logged_warnings).to eq ''
290
+ expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy5)
291
+ end
292
+
293
+ it "the new resource name can be used in a recipe" do
294
+ recipe = converge {
295
+ another_thingy_name_for_another_no_name_thingy5 'blah' do; end
296
+ }
297
+ expect(recipe.logged_warnings).to eq ''
298
+ expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy5)
299
+ end
300
+ end
301
+
302
+ context "With a resource named AnotherNoNameThingy6, a provides with the original resource name, and a different resource_name" do
303
+ before(:context) {
304
+
305
+ class AnotherNoNameThingy6 < BaseThingy
306
+ provides :another_no_name_thingy6, os: 'blarghle'
307
+ resource_name :another_thingy_name_for_another_no_name_thingy6
308
+ end
309
+
310
+ }
311
+
312
+ it "and os = linux, another_no_name_thingy6 does not work" do
313
+ expect_converge {
314
+ # this is an ugly way to test, make Cheffish expose node attrs
315
+ run_context.node.automatic[:os] = 'linux'
316
+ another_no_name_thingy6 'blah' do; end
317
+ }.to raise_error(Chef::Exceptions::NoSuchResourceType)
318
+ end
319
+
320
+ it "and os = blarghle, another_no_name_thingy6 works" do
321
+ recipe = converge {
322
+ # this is an ugly way to test, make Cheffish expose node attrs
323
+ run_context.node.automatic[:os] = 'blarghle'
324
+ another_no_name_thingy6 'blah' do; end
325
+ }
326
+ expect(recipe.logged_warnings).to eq ''
327
+ expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy6)
328
+ end
329
+
330
+ it "the new resource name can be used in a recipe" do
331
+ recipe = converge {
332
+ another_thingy_name_for_another_no_name_thingy6 'blah' do; end
333
+ }
334
+ expect(recipe.logged_warnings).to eq ''
335
+ expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy6)
336
+ end
337
+ end
338
+
339
+ context "With a resource named AnotherNoNameThingy7, a new resource_name, and provides with that new resource name" do
340
+ before(:context) {
341
+
342
+ class AnotherNoNameThingy7 < BaseThingy
343
+ resource_name :another_thingy_name_for_another_no_name_thingy7
344
+ provides :another_thingy_name_for_another_no_name_thingy7, os: 'blarghle'
345
+ end
346
+
347
+ }
348
+
349
+ it "and os = linux, another_thingy_name_for_another_no_name_thingy7 does not work" do
350
+ expect_converge {
351
+ # this is an ugly way to test, make Cheffish expose node attrs
352
+ run_context.node.automatic[:os] = 'linux'
353
+ another_thingy_name_for_another_no_name_thingy7 'blah' do; end
354
+ }.to raise_error(Chef::Exceptions::NoSuchResourceType)
355
+ end
356
+
357
+ it "and os = blarghle, another_thingy_name_for_another_no_name_thingy7 works" do
358
+ recipe = converge {
359
+ # this is an ugly way to test, make Cheffish expose node attrs
360
+ run_context.node.automatic[:os] = 'blarghle'
361
+ another_thingy_name_for_another_no_name_thingy7 'blah' do; end
362
+ }
363
+ expect(recipe.logged_warnings).to eq ''
364
+ expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy7)
365
+ end
366
+
367
+ it "the old resource name does not work" do
368
+ expect_converge {
369
+ # this is an ugly way to test, make Cheffish expose node attrs
370
+ run_context.node.automatic[:os] = 'linux'
371
+ another_no_name_thingy_7 'blah' do; end
372
+ }.to raise_error(NoMethodError)
373
+ end
374
+ end
375
+
376
+ # opposite order from the previous test (provides, then resource_name)
377
+ context "With a resource named AnotherNoNameThingy8, a provides with a new resource name, and resource_name with that new resource name" do
378
+ before(:context) {
379
+
380
+ class AnotherNoNameThingy8 < BaseThingy
381
+ provides :another_thingy_name_for_another_no_name_thingy8, os: 'blarghle'
382
+ resource_name :another_thingy_name_for_another_no_name_thingy8
383
+ end
384
+
385
+ }
386
+
387
+ it "and os = linux, another_thingy_name_for_another_no_name_thingy8 does not work" do
388
+ expect_converge {
389
+ # this is an ugly way to test, make Cheffish expose node attrs
390
+ run_context.node.automatic[:os] = 'linux'
391
+ another_thingy_name_for_another_no_name_thingy8 'blah' do; end
392
+ }.to raise_error(Chef::Exceptions::NoSuchResourceType)
393
+ end
394
+
395
+ it "and os = blarghle, another_thingy_name_for_another_no_name_thingy8 works" do
396
+ recipe = converge {
397
+ # this is an ugly way to test, make Cheffish expose node attrs
398
+ run_context.node.automatic[:os] = 'blarghle'
399
+ another_thingy_name_for_another_no_name_thingy8 'blah' do; end
400
+ }
401
+ expect(recipe.logged_warnings).to eq ''
402
+ expect(BaseThingy.created_resource).to eq (AnotherNoNameThingy8)
403
+ end
404
+
405
+ it "the old resource name does not work" do
406
+ expect_converge {
407
+ # this is an ugly way to test, make Cheffish expose node attrs
408
+ run_context.node.automatic[:os] = 'linux'
409
+ another_thingy_name8 'blah' do; end
410
+ }.to raise_error(NoMethodError)
411
+ end
412
+ end
413
+
414
+ context "With a resource TwoClassesOneDsl" do
415
+ let(:class_name) { "TwoClassesOneDsl#{Namer.current_index}" }
416
+ let(:dsl_method) { :"two_classes_one_dsl#{Namer.current_index}" }
417
+
418
+ before {
419
+ eval <<-EOM, nil, __FILE__, __LINE__+1
420
+ class #{class_name} < BaseThingy
421
+ end
422
+ EOM
423
+ }
424
+ context "and resource BlahModule::TwoClassesOneDsl" do
425
+ before {
426
+ eval <<-EOM, nil, __FILE__, __LINE__+1
427
+ module BlahModule
428
+ class #{class_name} < BaseThingy
429
+ end
430
+ end
431
+ EOM
432
+ }
433
+ it "two_classes_one_dsl resolves to BlahModule::TwoClassesOneDsl (last declared)" do
434
+ dsl_method = self.dsl_method
435
+ recipe = converge {
436
+ instance_eval("#{dsl_method} 'blah' do; end")
437
+ }
438
+ expect(recipe.logged_warnings).to eq ''
439
+ expect(BaseThingy.created_resource).to eq eval("BlahModule::#{class_name}")
440
+ end
441
+ it "resource_matching_short_name returns BlahModule::TwoClassesOneDsl" do
442
+ expect(Chef::Resource.resource_matching_short_name(dsl_method)).to eq eval("BlahModule::#{class_name}")
443
+ end
444
+ end
445
+ context "and resource BlahModule::TwoClassesOneDsl with resource_name nil" do
446
+ before {
447
+ eval <<-EOM, nil, __FILE__, __LINE__+1
448
+ module BlahModule
449
+ class BlahModule::#{class_name} < BaseThingy
450
+ resource_name nil
451
+ end
452
+ end
453
+ EOM
454
+ }
455
+ it "two_classes_one_dsl resolves to ::TwoClassesOneDsl" do
456
+ dsl_method = self.dsl_method
457
+ recipe = converge {
458
+ instance_eval("#{dsl_method} 'blah' do; end")
459
+ }
460
+ expect(recipe.logged_warnings).to eq ''
461
+ expect(BaseThingy.created_resource).to eq eval("::#{class_name}")
462
+ end
463
+ it "resource_matching_short_name returns ::TwoClassesOneDsl" do
464
+ expect(Chef::Resource.resource_matching_short_name(dsl_method)).to eq eval("::#{class_name}")
465
+ end
466
+ end
467
+ context "and resource BlahModule::TwoClassesOneDsl with resource_name :argh" do
468
+ before {
469
+ eval <<-EOM, nil, __FILE__, __LINE__+1
470
+ module BlahModule
471
+ class BlahModule::#{class_name} < BaseThingy
472
+ resource_name :argh
473
+ end
474
+ end
475
+ EOM
476
+ }
477
+ it "two_classes_one_dsl resolves to ::TwoClassesOneDsl" do
478
+ dsl_method = self.dsl_method
479
+ recipe = converge {
480
+ instance_eval("#{dsl_method} 'blah' do; end")
481
+ }
482
+ expect(recipe.logged_warnings).to eq ''
483
+ expect(BaseThingy.created_resource).to eq eval("::#{class_name}")
484
+ end
485
+ it "resource_matching_short_name returns ::TwoClassesOneDsl" do
486
+ expect(Chef::Resource.resource_matching_short_name(dsl_method)).to eq eval("::#{class_name}")
487
+ end
488
+ end
489
+ context "and resource BlahModule::TwoClassesOneDsl with provides :two_classes_one_dsl, os: 'blarghle'" do
490
+ before {
491
+ eval <<-EOM, nil, __FILE__, __LINE__+1
492
+ module BlahModule
493
+ class BlahModule::#{class_name} < BaseThingy
494
+ provides #{dsl_method.inspect}, os: 'blarghle'
495
+ end
496
+ end
497
+ EOM
498
+ }
499
+
500
+ it "and os = blarghle, two_classes_one_dsl resolves to BlahModule::TwoClassesOneDsl" do
501
+ dsl_method = self.dsl_method
502
+ recipe = converge {
503
+ # this is an ugly way to test, make Cheffish expose node attrs
504
+ run_context.node.automatic[:os] = 'blarghle'
505
+ instance_eval("#{dsl_method} 'blah' do; end")
506
+ }
507
+ expect(recipe.logged_warnings).to eq ''
508
+ expect(BaseThingy.created_resource).to eq eval("BlahModule::#{class_name}")
509
+ end
510
+
511
+ it "and os = linux, two_classes_one_dsl resolves to ::TwoClassesOneDsl" do
512
+ dsl_method = self.dsl_method
513
+ recipe = converge {
514
+ # this is an ugly way to test, make Cheffish expose node attrs
515
+ run_context.node.automatic[:os] = 'linux'
516
+ instance_eval("#{dsl_method} 'blah' do; end")
517
+ }
518
+ expect(recipe.logged_warnings).to eq ''
519
+ expect(BaseThingy.created_resource).to eq eval("::#{class_name}")
520
+ end
521
+ end
522
+ end
523
+ end
114
524
  end
115
525
 
116
526
  context "provides" do
117
- context "When MySupplier provides :hemlock" do
527
+ context "when MySupplier provides :hemlock" do
118
528
  before(:context) {
119
529
 
120
530
  class RecipeDSLSpecNamespace::MySupplier < BaseThingy
121
- provides :hemlock
531
+ resource_name :hemlock
122
532
  end
123
533
 
124
534
  }
@@ -137,11 +547,11 @@ describe "Recipe DSL methods" do
137
547
  end
138
548
  end
139
549
 
140
- context "When Thingy3 provides :thingy3" do
550
+ context "when Thingy3 has resource_name :thingy3" do
141
551
  before(:context) {
142
552
 
143
553
  class RecipeDSLSpecNamespace::Thingy3 < BaseThingy
144
- provides :thingy3
554
+ resource_name :thingy3
145
555
  end
146
556
 
147
557
  }
@@ -153,21 +563,20 @@ describe "Recipe DSL methods" do
153
563
  expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy3
154
564
  end
155
565
 
156
- context "And Thingy4 provides :thingy3" do
566
+ context "and Thingy4 has resource_name :thingy3" do
157
567
  before(:context) {
158
568
 
159
- class RecipeDSLSpecNamespace::Thingy4 < Chef::Resource
160
- provides :thingy3
569
+ class RecipeDSLSpecNamespace::Thingy4 < BaseThingy
570
+ resource_name :thingy3
161
571
  end
162
572
 
163
573
  }
164
574
 
165
- it "thingy3 works in a recipe and yields " do
575
+ it "thingy3 works in a recipe and yields Foo::Thingy4 (the explicit one)" do
166
576
  recipe = converge {
167
577
  thingy3 'blah' do; end
168
578
  }
169
- expect(recipe.logged_warnings).to match(/ambiguous resource precedence/i)
170
- expect(BaseThingy.created_resource).not_to be_nil
579
+ expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy4
171
580
  end
172
581
 
173
582
  it "thingy4 does not work in a recipe" do
@@ -175,14 +584,101 @@ describe "Recipe DSL methods" do
175
584
  thingy4 'blah' do; end
176
585
  }.to raise_error(NoMethodError)
177
586
  end
587
+
588
+ it "resource_matching_short_name returns Thingy4" do
589
+ expect(Chef::Resource.resource_matching_short_name(:thingy3)).to eq RecipeDSLSpecNamespace::Thingy4
590
+ end
591
+ end
592
+ end
593
+
594
+ context "when Thingy5 has resource_name :thingy5" do
595
+ before(:context) {
596
+
597
+ class RecipeDSLSpecNamespace::Thingy5 < BaseThingy
598
+ resource_name :thingy5
599
+ end
600
+
601
+ }
602
+
603
+ it "thingy5 works in a recipe" do
604
+ expect_recipe {
605
+ thingy5 'blah' do; end
606
+ }.to emit_no_warnings_or_errors
607
+ expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy5
608
+ end
609
+
610
+ context "and Thingy6 provides :thingy5" do
611
+ before(:context) {
612
+
613
+ class RecipeDSLSpecNamespace::Thingy6 < BaseThingy
614
+ provides :thingy5
615
+ end
616
+
617
+ }
618
+
619
+ it "thingy6 works in a recipe and yields Thingy6" do
620
+ recipe = converge {
621
+ thingy6 'blah' do; end
622
+ }
623
+ expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy6
624
+ end
625
+
626
+ it "thingy5 works in a recipe and yields Foo::Thingy6 (the later one)" do
627
+ recipe = converge {
628
+ thingy5 'blah' do; end
629
+ }
630
+ expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy6
631
+ end
632
+
633
+ it "resource_matching_short_name returns Thingy5" do
634
+ expect(Chef::Resource.resource_matching_short_name(:thingy5)).to eq RecipeDSLSpecNamespace::Thingy5
635
+ end
636
+ end
637
+ end
638
+
639
+ context "when Thingy7 provides :thingy8" do
640
+ before(:context) {
641
+
642
+ class RecipeDSLSpecNamespace::Thingy7 < BaseThingy
643
+ provides :thingy8
644
+ end
645
+
646
+ }
647
+
648
+ context "and Thingy8 has resource_name :thingy8" do
649
+ before(:context) {
650
+
651
+ class RecipeDSLSpecNamespace::Thingy8 < BaseThingy
652
+ resource_name :thingy8
653
+ end
654
+
655
+ }
656
+
657
+ it "thingy7 works in a recipe and yields Thingy7" do
658
+ recipe = converge {
659
+ thingy7 'blah' do; end
660
+ }
661
+ expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy7
662
+ end
663
+
664
+ it "thingy8 works in a recipe and yields Thingy8 (the later one)" do
665
+ recipe = converge {
666
+ thingy8 'blah' do; end
667
+ }
668
+ expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy8
669
+ end
670
+
671
+ it "resource_matching_short_name returns Thingy8" do
672
+ expect(Chef::Resource.resource_matching_short_name(:thingy8)).to eq RecipeDSLSpecNamespace::Thingy8
673
+ end
178
674
  end
179
675
  end
180
676
 
181
- context "When Thingy5 provides :thingy5, :twizzle and :twizzle2" do
677
+ context "when Thingy5 provides :thingy5, :twizzle and :twizzle2" do
182
678
  before(:context) {
183
679
 
184
680
  class RecipeDSLSpecNamespace::Thingy5 < BaseThingy
185
- provides :thingy5
681
+ resource_name :thingy5
186
682
  provides :twizzle
187
683
  provides :twizzle2
188
684
  end
@@ -214,10 +710,12 @@ describe "Recipe DSL methods" do
214
710
  context "With platform-specific resources 'my_super_thingy_foo' and 'my_super_thingy_bar'" do
215
711
  before(:context) {
216
712
  class MySuperThingyFoo < BaseThingy
713
+ resource_name :my_super_thingy_foo
217
714
  provides :my_super_thingy, platform: 'foo'
218
715
  end
219
716
 
220
717
  class MySuperThingyBar < BaseThingy
718
+ resource_name :my_super_thingy_bar
221
719
  provides :my_super_thingy, platform: 'bar'
222
720
  end
223
721
  }