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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/distro/powershell/chef/chef.psm1 +327 -0
  3. data/lib/chef/chef_class.rb +4 -4
  4. data/lib/chef/client.rb +12 -6
  5. data/lib/chef/node_map.rb +63 -38
  6. data/lib/chef/platform/priority_map.rb +54 -0
  7. data/lib/chef/platform/provider_mapping.rb +2 -2
  8. data/lib/chef/platform/provider_priority_map.rb +3 -21
  9. data/lib/chef/platform/resource_priority_map.rb +5 -22
  10. data/lib/chef/provider.rb +1 -1
  11. data/lib/chef/provider/package/rpm.rb +2 -2
  12. data/lib/chef/provider/service/debian.rb +0 -2
  13. data/lib/chef/provider/service/insserv.rb +0 -2
  14. data/lib/chef/provider/service/invokercd.rb +0 -2
  15. data/lib/chef/provider/service/redhat.rb +0 -2
  16. data/lib/chef/provider/service/upstart.rb +0 -2
  17. data/lib/chef/provider/user.rb +0 -2
  18. data/lib/chef/resource.rb +23 -24
  19. data/lib/chef/resource/lwrp_base.rb +2 -1
  20. data/lib/chef/resource/macports_package.rb +2 -1
  21. data/lib/chef/resource/package.rb +0 -5
  22. data/lib/chef/resource_resolver.rb +1 -0
  23. data/lib/chef/version.rb +1 -1
  24. data/spec/integration/recipes/lwrp_spec.rb +2 -6
  25. data/spec/integration/recipes/recipe_dsl_spec.rb +254 -39
  26. data/spec/support/shared/shared_examples.rb +1 -1
  27. data/spec/unit/api_client_spec.rb +1 -1
  28. data/spec/unit/client_spec.rb +35 -19
  29. data/spec/unit/cookbook_version_spec.rb +1 -1
  30. data/spec/unit/data_bag_item_spec.rb +1 -1
  31. data/spec/unit/data_bag_spec.rb +1 -1
  32. data/spec/unit/environment_spec.rb +1 -1
  33. data/spec/unit/exceptions_spec.rb +1 -1
  34. data/spec/unit/json_compat_spec.rb +1 -1
  35. data/spec/unit/lwrp_spec.rb +43 -4
  36. data/spec/unit/node_spec.rb +1 -1
  37. data/spec/unit/osc_user_spec.rb +1 -1
  38. data/spec/unit/provider/package/rpm_spec.rb +335 -124
  39. data/spec/unit/provider_resolver_spec.rb +0 -1
  40. data/spec/unit/recipe_spec.rb +12 -8
  41. data/spec/unit/resource_collection_spec.rb +1 -1
  42. data/spec/unit/resource_resolver_spec.rb +49 -0
  43. data/spec/unit/resource_spec.rb +19 -4
  44. data/spec/unit/role_spec.rb +1 -1
  45. data/spec/unit/run_list_spec.rb +1 -1
  46. data/spec/unit/runner_spec.rb +2 -2
  47. data/spec/unit/user_spec.rb +1 -1
  48. metadata +10 -8
  49. data/spec/support/pedant/Gemfile.lock +0 -67
@@ -0,0 +1,54 @@
1
+ require 'chef/node_map'
2
+
3
+ class Chef
4
+ class Platform
5
+ class PriorityMap < Chef::NodeMap
6
+ def priority(resource_name, priority_array, *filter)
7
+ set_priority_array(resource_name.to_sym, priority_array, *filter)
8
+ end
9
+
10
+ # @api private
11
+ def get_priority_array(node, key)
12
+ get(node, key)
13
+ end
14
+
15
+ # @api private
16
+ def set_priority_array(key, priority_array, *filter, &block)
17
+ priority_array = Array(priority_array)
18
+ set(key, priority_array, *filter, &block)
19
+ priority_array
20
+ end
21
+
22
+ # @api private
23
+ def list_handlers(node, key, **filters)
24
+ list(node, key, **filters).flatten(1).uniq
25
+ end
26
+
27
+ #
28
+ # Priority maps have one extra precedence: priority arrays override "provides,"
29
+ # and "provides" lines with identical filters sort by class name (ascending).
30
+ #
31
+ def compare_matchers(key, new_matcher, matcher)
32
+ # Priority arrays come before "provides"
33
+ if new_matcher[:value].is_a?(Array) != matcher[:value].is_a?(Array)
34
+ return new_matcher[:value].is_a?(Array) ? -1 : 1
35
+ end
36
+
37
+ cmp = super
38
+ if cmp == 0
39
+ # Sort by class name (ascending) as well, if all other properties
40
+ # are exactly equal
41
+ if new_matcher[:value].is_a?(Class) && !new_matcher[:override]
42
+ cmp = compare_matcher_properties(new_matcher, matcher) { |m| m[:value].name }
43
+ if cmp < 0
44
+ Chef::Log.warn "You are overriding #{key} on #{new_matcher[:filters].inspect} with #{new_matcher[:value].inspect}: used to be #{matcher[:value].inspect}. Use override: true if this is what you intended."
45
+ elsif cmp > 0
46
+ Chef::Log.warn "You declared a new resource #{new_matcher[:value].inspect} for resource #{key}, but it comes alphabetically after #{matcher[:value].inspect} and has the same filters (#{new_matcher[:filters].inspect}), so it will not be used. Use override: true if you want to use it for #{key}."
47
+ end
48
+ end
49
+ end
50
+ cmp
51
+ end
52
+ end
53
+ end
54
+ end
@@ -201,8 +201,8 @@ class Chef
201
201
 
202
202
  begin
203
203
  result = Chef::Provider.const_get(class_name)
204
- Chef::Log.warn("Class Chef::Provider::#{class_name} does not declare 'provides #{convert_to_snake_case(class_name).to_sym.inspect}'.")
205
- Chef::Log.warn("This will no longer work in Chef 13: you must use 'provides' to provide DSL.")
204
+ Chef::Log.warn("Class Chef::Provider::#{class_name} does not declare 'resource_name #{convert_to_snake_case(class_name).to_sym.inspect}'.")
205
+ Chef::Log.warn("This will no longer work in Chef 13: you must use 'resource_name' to provide DSL.")
206
206
  rescue NameError
207
207
  end
208
208
  end
@@ -1,29 +1,11 @@
1
1
  require 'singleton'
2
+ require 'chef/platform/priority_map'
2
3
 
3
4
  class Chef
4
5
  class Platform
5
- class ProviderPriorityMap
6
+ # @api private
7
+ class ProviderPriorityMap < Chef::Platform::PriorityMap
6
8
  include Singleton
7
-
8
- def get_priority_array(node, resource_name)
9
- priority_map.get(node, resource_name.to_sym)
10
- end
11
-
12
- def set_priority_array(resource_name, priority_array, *filter, &block)
13
- priority_map.set(resource_name.to_sym, Array(priority_array), *filter, &block)
14
- end
15
-
16
- # @api private
17
- def list_handlers(node, resource_name)
18
- priority_map.list(node, resource_name.to_sym).flatten(1).uniq
19
- end
20
-
21
- private
22
-
23
- def priority_map
24
- require 'chef/node_map'
25
- @priority_map ||= Chef::NodeMap.new
26
- end
27
9
  end
28
10
  end
29
11
  end
@@ -1,34 +1,17 @@
1
1
  require 'singleton'
2
+ require 'chef/platform/priority_map'
2
3
 
3
4
  class Chef
4
5
  class Platform
5
- class ResourcePriorityMap
6
+ # @api private
7
+ class ResourcePriorityMap < Chef::Platform::PriorityMap
6
8
  include Singleton
7
9
 
8
- def get_priority_array(node, resource_name, canonical: nil)
9
- priority_map.get(node, resource_name.to_sym, canonical: canonical)
10
- end
11
-
12
- def set_priority_array(resource_name, priority_array, *filter, &block)
13
- priority_map.set(resource_name.to_sym, Array(priority_array), *filter, &block)
14
- end
15
-
16
10
  # @api private
17
- def delete_canonical(resource_name, resource_class)
18
- priority_map.delete_canonical(resource_name, resource_class)
19
- end
20
-
21
- # @api private
22
- def list_handlers(*args)
23
- priority_map.list(*args).flatten(1).uniq
11
+ def get_priority_array(node, resource_name, canonical: nil)
12
+ super(node, resource_name.to_sym, canonical: canonical)
24
13
  end
25
14
 
26
- private
27
-
28
- def priority_map
29
- require 'chef/node_map'
30
- @priority_map ||= Chef::NodeMap.new
31
- end
32
15
  end
33
16
  end
34
17
  end
data/lib/chef/provider.rb CHANGED
@@ -176,7 +176,7 @@ class Chef
176
176
  end
177
177
 
178
178
  def self.provides(short_name, opts={}, &block)
179
- Chef.set_provider_priority_array(short_name, self, opts, &block)
179
+ Chef.provider_priority_map.set(short_name, self, opts, &block)
180
180
  end
181
181
 
182
182
  def self.provides?(node, resource)
@@ -61,7 +61,7 @@ class Chef
61
61
  Chef::Log.debug("#{@new_resource} checking rpm status")
62
62
  shell_out_with_timeout!("rpm -qp --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' #{@new_resource.source}").stdout.each_line do |line|
63
63
  case line
64
- when /^([\w\d+_.-]+)\s([\w\d_.-]+)$/
64
+ when /^([\w\d+_.-]+)\s([\w\d~_.-]+)$/
65
65
  @current_resource.package_name($1)
66
66
  @new_resource.version($2)
67
67
  @candidate_version = $2
@@ -78,7 +78,7 @@ class Chef
78
78
  @rpm_status = shell_out_with_timeout("rpm -q --queryformat '%{NAME} %{VERSION}-%{RELEASE}\n' #{@current_resource.package_name}")
79
79
  @rpm_status.stdout.each_line do |line|
80
80
  case line
81
- when /^([\w\d+_.-]+)\s([\w\d_.-]+)$/
81
+ when /^([\w\d+_.-]+)\s([\w\d~_.-]+)$/
82
82
  Chef::Log.debug("#{@new_resource} current version is #{$2}")
83
83
  @current_resource.version($2)
84
84
  end
@@ -25,8 +25,6 @@ class Chef
25
25
  UPDATE_RC_D_ENABLED_MATCHES = /\/rc[\dS].d\/S|not installed/i
26
26
  UPDATE_RC_D_PRIORITIES = /\/rc([\dS]).d\/([SK])(\d\d)/i
27
27
 
28
- provides :service, platform_family: "debian"
29
-
30
28
  def self.provides?(node, resource)
31
29
  super && Chef::Platform::ServiceHelpers.service_resource_providers.include?(:debian)
32
30
  end
@@ -24,8 +24,6 @@ class Chef
24
24
  class Service
25
25
  class Insserv < Chef::Provider::Service::Init
26
26
 
27
- provides :service, os: "linux"
28
-
29
27
  def self.provides?(node, resource)
30
28
  super && Chef::Platform::ServiceHelpers.service_resource_providers.include?(:insserv)
31
29
  end
@@ -23,8 +23,6 @@ class Chef
23
23
  class Service
24
24
  class Invokercd < Chef::Provider::Service::Init
25
25
 
26
- provides :service, platform_family: "debian"
27
-
28
26
  def self.provides?(node, resource)
29
27
  super && Chef::Platform::ServiceHelpers.service_resource_providers.include?(:invokercd)
30
28
  end
@@ -26,8 +26,6 @@ class Chef
26
26
  CHKCONFIG_ON = /\d:on/
27
27
  CHKCONFIG_MISSING = /No such/
28
28
 
29
- provides :service, platform_family: [ "rhel", "fedora", "suse" ]
30
-
31
29
  def self.provides?(node, resource)
32
30
  super && Chef::Platform::ServiceHelpers.service_resource_providers.include?(:redhat)
33
31
  end
@@ -27,8 +27,6 @@ class Chef
27
27
  class Upstart < Chef::Provider::Service::Simple
28
28
  UPSTART_STATE_FORMAT = /\w+ \(?(\w+)\)?[\/ ](\w+)/
29
29
 
30
- provides :service, os: "linux"
31
-
32
30
  def self.provides?(node, resource)
33
31
  super && Chef::Platform::ServiceHelpers.service_resource_providers.include?(:upstart)
34
32
  end
@@ -23,8 +23,6 @@ require 'etc'
23
23
  class Chef
24
24
  class Provider
25
25
  class User < Chef::Provider
26
- provides :user
27
-
28
26
  include Chef::Mixin::Command
29
27
 
30
28
  attr_accessor :user_exists, :locked
data/lib/chef/resource.rb CHANGED
@@ -924,11 +924,6 @@ class Chef
924
924
  else
925
925
  @resource_name = nil
926
926
  end
927
- else
928
- # set resource_name automatically if it's not set
929
- if !instance_variable_defined?(:@resource_name) && self.name
930
- resource_name convert_to_snake_case(self.name.split('::')[-1])
931
- end
932
927
  end
933
928
 
934
929
  @resource_name
@@ -965,7 +960,7 @@ class Chef
965
960
  #
966
961
  # @param actions [Array<Symbol>] The list of actions to add to allowed_actions.
967
962
  #
968
- # @return [Arrau<Symbol>] The list of actions, as symbols.
963
+ # @return [Array<Symbol>] The list of actions, as symbols.
969
964
  #
970
965
  def self.allowed_actions(*actions)
971
966
  @allowed_actions ||=
@@ -974,10 +969,10 @@ class Chef
974
969
  else
975
970
  [ :nothing ]
976
971
  end
977
- @allowed_actions |= actions
972
+ @allowed_actions |= actions.flatten
978
973
  end
979
974
  def self.allowed_actions=(value)
980
- @allowed_actions = value
975
+ @allowed_actions = value.uniq
981
976
  end
982
977
 
983
978
  #
@@ -1111,7 +1106,12 @@ class Chef
1111
1106
  def self.inherited(child)
1112
1107
  super
1113
1108
  @sorted_descendants = nil
1114
- child.resource_name
1109
+ # set resource_name automatically if it's not set
1110
+ if child.name && !child.resource_name
1111
+ if child.name =~ /^Chef::Resource::(\w+)$/
1112
+ child.resource_name(convert_to_snake_case($1))
1113
+ end
1114
+ end
1115
1115
  end
1116
1116
 
1117
1117
 
@@ -1143,7 +1143,7 @@ class Chef
1143
1143
  remove_canonical_dsl
1144
1144
  end
1145
1145
 
1146
- result = Chef.set_resource_priority_array(name, self, options, &block)
1146
+ result = Chef.resource_priority_map.set(name, self, options, &block)
1147
1147
  Chef::DSL::Resources.add_resource_dsl(name)
1148
1148
  result
1149
1149
  end
@@ -1318,23 +1318,22 @@ class Chef
1318
1318
  # when Chef::Resource::MyLwrp
1319
1319
  # end
1320
1320
  #
1321
- resource_subclass = class_eval <<-EOM, __FILE__, __LINE__+1
1322
- class Chef::Resource::#{class_name} < resource_class
1323
- resource_name nil # we do not actually provide anything
1324
- def initialize(*args, &block)
1325
- Chef::Log.deprecation("Using an LWRP by its name (#{class_name}) directly is no longer supported in Chef 13 and will be removed. Use Chef::Resource.resource_for_node(node, name) instead.")
1321
+ resource_subclass = Class.new(resource_class) do
1322
+ resource_name nil # we do not actually provide anything
1323
+ def initialize(*args, &block)
1324
+ Chef::Log.deprecation("Using an LWRP by its name (#{self.class.name}) directly is no longer supported in Chef 13 and will be removed. Use Chef::Resource.resource_for_node(node, name) instead.")
1325
+ super
1326
+ end
1327
+ def self.resource_name(*args)
1328
+ if args.empty?
1329
+ @resource_name ||= superclass.resource_name
1330
+ else
1326
1331
  super
1327
1332
  end
1328
- def self.resource_name(*args)
1329
- if args.empty?
1330
- @resource_name ||= superclass.resource_name
1331
- else
1332
- super
1333
- end
1334
- end
1335
- self
1336
1333
  end
1337
- EOM
1334
+ self
1335
+ end
1336
+ eval("Chef::Resource::#{class_name} = resource_subclass")
1338
1337
  # Make case, is_a and kind_of work with the new subclass, for backcompat.
1339
1338
  # Any subclass of Chef::Resource::ResourceClass is already a subclass of resource_class
1340
1339
  # Any subclass of resource_class is considered a subclass of Chef::Resource::ResourceClass
@@ -85,8 +85,9 @@ class Chef
85
85
  # Adds +action_names+ to the list of valid actions for this resource.
86
86
  # Does not include superclass's action list when appending.
87
87
  def actions(*action_names)
88
+ action_names = action_names.flatten
88
89
  if !action_names.empty? && !@allowed_actions
89
- self.allowed_actions = action_names
90
+ self.allowed_actions = ([ :nothing ] + action_names).uniq
90
91
  else
91
92
  allowed_actions(*action_names)
92
93
  end
@@ -16,10 +16,11 @@
16
16
  # limitations under the License.
17
17
  #
18
18
 
19
+ require 'chef/resource/package'
20
+
19
21
  class Chef
20
22
  class Resource
21
23
  class MacportsPackage < Chef::Resource::Package
22
- provides :package, os: "darwin"
23
24
  end
24
25
  end
25
26
  end
@@ -100,8 +100,3 @@ class Chef
100
100
  end
101
101
  end
102
102
  end
103
-
104
- require 'chef/chef_class'
105
- require 'chef/resource/homebrew_package'
106
-
107
- Chef.set_resource_priority_array :package, Chef::Resource::HomebrewPackage, os: "darwin"
@@ -18,6 +18,7 @@
18
18
 
19
19
  require 'chef/exceptions'
20
20
  require 'chef/platform/resource_priority_map'
21
+ require 'chef/mixin/convert_to_class_name'
21
22
 
22
23
  class Chef
23
24
  class ResourceResolver
data/lib/chef/version.rb CHANGED
@@ -21,7 +21,7 @@
21
21
 
22
22
  class Chef
23
23
  CHEF_ROOT = File.dirname(File.expand_path(File.dirname(__FILE__)))
24
- VERSION = '12.4.0.rc.2'
24
+ VERSION = '12.4.0'
25
25
  end
26
26
 
27
27
  #
@@ -45,12 +45,8 @@ log_level :warn
45
45
  EOM
46
46
 
47
47
  result = shell_out("#{chef_client} -c \"#{path_to('config/client.rb')}\" --no-color -F doc -o 'l-w-r-p::default'", :cwd => chef_dir)
48
- actual = result.stdout.lines.map { |l| l.chomp }.join("\n")
49
- expected = <<EOM
50
- * l_w_r_p_foo[me] action create (up to date)
51
- EOM
52
- expected = expected.lines.map { |l| l.chomp }.join("\n")
53
- expect(actual).to include(expected)
48
+ expect(result.stdout).to match(/\* l_w_r_p_foo\[me\] action create \(up to date\)/)
49
+ expect(result.stdout).not_to match(/WARN: You are overriding l_w_r_p_foo/)
54
50
  result.error!
55
51
  end
56
52
  end
@@ -15,13 +15,8 @@ describe "Recipe DSL methods" do
15
15
  before(:context) {
16
16
 
17
17
  class BaseThingy < Chef::Resource
18
- def initialize(*args, &block)
19
- super
20
- @allowed_actions = [ :create ]
21
- @action = :create
22
- end
23
-
24
18
  resource_name 'base_thingy'
19
+ default_action :create
25
20
 
26
21
  class<<self
27
22
  attr_accessor :created_resource
@@ -61,11 +56,7 @@ describe "Recipe DSL methods" do
61
56
  before(:context) {
62
57
 
63
58
  class Chef::Resource::BackcompatThingy < Chef::Resource
64
- def initialize(*args, &block)
65
- super
66
- @allowed_actions = [ :create ]
67
- @action = :create
68
- end
59
+ default_action :create
69
60
  end
70
61
  class Chef::Provider::BackcompatThingy < Chef::Provider
71
62
  def load_current_resource
@@ -100,7 +91,7 @@ describe "Recipe DSL methods" do
100
91
  recipe = converge {
101
92
  backcompat_thingy 'blah' do; end
102
93
  }
103
- expect(recipe.logged_warnings).to eq ''
94
+ expect(recipe.logged_warnings).to match(/Class Chef::Provider::BackcompatThingy does not declare 'resource_name :backcompat_thingy'./)
104
95
  expect(BaseThingy.created_resource).not_to be_nil
105
96
  end
106
97
  end
@@ -114,19 +105,17 @@ describe "Recipe DSL methods" do
114
105
 
115
106
  }
116
107
 
117
- it "bar_thingy works" do
118
- recipe = converge {
108
+ it "bar_thingy does not work" do
109
+ expect_converge {
119
110
  bar_thingy 'blah' do; end
120
- }
121
- expect(recipe.logged_warnings).to eq ''
122
- expect(BaseThingy.created_resource).to eq(RecipeDSLSpecNamespace::Bar::BarThingy)
111
+ }.to raise_error(NoMethodError)
123
112
  end
124
113
  end
125
114
 
126
- context "With a resource named NoNameThingy with resource_name nil" do
115
+ context "With a resource named Chef::Resource::NoNameThingy with resource_name nil" do
127
116
  before(:context) {
128
117
 
129
- class NoNameThingy < BaseThingy
118
+ class Chef::Resource::NoNameThingy < BaseThingy
130
119
  resource_name nil
131
120
  end
132
121
 
@@ -134,7 +123,7 @@ describe "Recipe DSL methods" do
134
123
 
135
124
  it "no_name_thingy does not work" do
136
125
  expect_converge {
137
- thingy 'blah' do; end
126
+ no_name_thingy 'blah' do; end
138
127
  }.to raise_error(NoMethodError)
139
128
  end
140
129
  end
@@ -199,6 +188,7 @@ describe "Recipe DSL methods" do
199
188
  before(:context) {
200
189
 
201
190
  class AnotherNoNameThingy3 < BaseThingy
191
+ resource_name :another_no_name_thingy_3
202
192
  provides :another_no_name_thingy3, os: 'blarghle'
203
193
  end
204
194
 
@@ -227,6 +217,7 @@ describe "Recipe DSL methods" do
227
217
  before(:context) {
228
218
 
229
219
  class AnotherNoNameThingy4 < BaseThingy
220
+ resource_name :another_no_name_thingy_4
230
221
  provides :another_no_name_thingy4, os: 'blarghle'
231
222
  provides :another_no_name_thingy4, platform_family: 'foo'
232
223
  end
@@ -418,6 +409,7 @@ describe "Recipe DSL methods" do
418
409
  before {
419
410
  eval <<-EOM, nil, __FILE__, __LINE__+1
420
411
  class #{class_name} < BaseThingy
412
+ resource_name #{dsl_method.inspect}
421
413
  end
422
414
  EOM
423
415
  }
@@ -426,11 +418,12 @@ describe "Recipe DSL methods" do
426
418
  eval <<-EOM, nil, __FILE__, __LINE__+1
427
419
  module BlahModule
428
420
  class #{class_name} < BaseThingy
421
+ resource_name #{dsl_method.inspect}
429
422
  end
430
423
  end
431
424
  EOM
432
425
  }
433
- it "two_classes_one_dsl resolves to BlahModule::TwoClassesOneDsl (last declared)" do
426
+ it "two_classes_one_dsl resolves to BlahModule::TwoClassesOneDsl (alphabetical)" do
434
427
  dsl_method = self.dsl_method
435
428
  recipe = converge {
436
429
  instance_eval("#{dsl_method} 'blah' do; end")
@@ -491,6 +484,7 @@ describe "Recipe DSL methods" do
491
484
  eval <<-EOM, nil, __FILE__, __LINE__+1
492
485
  module BlahModule
493
486
  class BlahModule::#{class_name} < BaseThingy
487
+ resource_name #{dsl_method.inspect}
494
488
  provides #{dsl_method.inspect}, os: 'blarghle'
495
489
  end
496
490
  end
@@ -572,11 +566,11 @@ describe "Recipe DSL methods" do
572
566
 
573
567
  }
574
568
 
575
- it "thingy3 works in a recipe and yields Foo::Thingy4 (the explicit one)" do
569
+ it "thingy3 works in a recipe and yields Thingy3 (the alphabetical one)" do
576
570
  recipe = converge {
577
571
  thingy3 'blah' do; end
578
572
  }
579
- expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy4
573
+ expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy3
580
574
  end
581
575
 
582
576
  it "thingy4 does not work in a recipe" do
@@ -586,16 +580,19 @@ describe "Recipe DSL methods" do
586
580
  end
587
581
 
588
582
  it "resource_matching_short_name returns Thingy4" do
589
- expect(Chef::Resource.resource_matching_short_name(:thingy3)).to eq RecipeDSLSpecNamespace::Thingy4
583
+ expect(Chef::Resource.resource_matching_short_name(:thingy3)).to eq RecipeDSLSpecNamespace::Thingy3
590
584
  end
591
585
  end
592
586
  end
593
587
 
594
- context "when Thingy5 has resource_name :thingy5" do
588
+ context "when Thingy5 has resource_name :thingy5 and provides :thingy5reverse, :thingy5_2 and :thingy5_2reverse" do
595
589
  before(:context) {
596
590
 
597
591
  class RecipeDSLSpecNamespace::Thingy5 < BaseThingy
598
592
  resource_name :thingy5
593
+ provides :thingy5reverse
594
+ provides :thingy5_2
595
+ provides :thingy5_2reverse
599
596
  end
600
597
 
601
598
  }
@@ -611,6 +608,7 @@ describe "Recipe DSL methods" do
611
608
  before(:context) {
612
609
 
613
610
  class RecipeDSLSpecNamespace::Thingy6 < BaseThingy
611
+ resource_name :thingy6
614
612
  provides :thingy5
615
613
  end
616
614
 
@@ -623,23 +621,151 @@ describe "Recipe DSL methods" do
623
621
  expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy6
624
622
  end
625
623
 
626
- it "thingy5 works in a recipe and yields Foo::Thingy6 (the later one)" do
624
+ it "thingy5 works in a recipe and yields Foo::Thingy5 (the alphabetical one)" do
627
625
  recipe = converge {
628
626
  thingy5 'blah' do; end
629
627
  }
630
- expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy6
628
+ expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy5
631
629
  end
632
630
 
633
631
  it "resource_matching_short_name returns Thingy5" do
634
632
  expect(Chef::Resource.resource_matching_short_name(:thingy5)).to eq RecipeDSLSpecNamespace::Thingy5
635
633
  end
634
+
635
+ context "and AThingy5 provides :thingy5reverse" do
636
+ before(:context) {
637
+
638
+ class RecipeDSLSpecNamespace::AThingy5 < BaseThingy
639
+ resource_name :thingy5reverse
640
+ end
641
+
642
+ }
643
+
644
+ it "thingy5reverse works in a recipe and yields AThingy5 (the alphabetical one)" do
645
+ recipe = converge {
646
+ thingy5reverse 'blah' do; end
647
+ }
648
+ expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::AThingy5
649
+ end
650
+ end
651
+
652
+ context "and ZRecipeDSLSpecNamespace::Thingy5 provides :thingy5_2" do
653
+ before(:context) {
654
+
655
+ module ZRecipeDSLSpecNamespace
656
+ class Thingy5 < BaseThingy
657
+ resource_name :thingy5_2
658
+ end
659
+ end
660
+
661
+ }
662
+
663
+ it "thingy5_2 works in a recipe and yields the RecipeDSLSpaceNamespace one (the alphabetical one)" do
664
+ recipe = converge {
665
+ thingy5_2 'blah' do; end
666
+ }
667
+ expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy5
668
+ end
669
+ end
670
+
671
+ context "and ARecipeDSLSpecNamespace::Thingy5 provides :thingy5_2" do
672
+ before(:context) {
673
+
674
+ module ARecipeDSLSpecNamespace
675
+ class Thingy5 < BaseThingy
676
+ resource_name :thingy5_2reverse
677
+ end
678
+ end
679
+
680
+ }
681
+
682
+ it "thingy5_2reverse works in a recipe and yields the ARecipeDSLSpaceNamespace one (the alphabetical one)" do
683
+ recipe = converge {
684
+ thingy5_2reverse 'blah' do; end
685
+ }
686
+ expect(BaseThingy.created_resource).to eq ARecipeDSLSpecNamespace::Thingy5
687
+ end
688
+ end
636
689
  end
690
+
691
+ context "when Thingy3 has resource_name :thingy3" do
692
+ before(:context) {
693
+
694
+ class RecipeDSLSpecNamespace::Thingy3 < BaseThingy
695
+ resource_name :thingy3
696
+ end
697
+
698
+ }
699
+
700
+ it "thingy3 works in a recipe" do
701
+ expect_recipe {
702
+ thingy3 'blah' do; end
703
+ }.to emit_no_warnings_or_errors
704
+ expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy3
705
+ end
706
+
707
+ context "and Thingy4 has resource_name :thingy3" do
708
+ before(:context) {
709
+
710
+ class RecipeDSLSpecNamespace::Thingy4 < BaseThingy
711
+ resource_name :thingy3
712
+ end
713
+
714
+ }
715
+
716
+ it "thingy3 works in a recipe and yields Thingy3 (the alphabetical one)" do
717
+ recipe = converge {
718
+ thingy3 'blah' do; end
719
+ }
720
+ expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy3
721
+ end
722
+
723
+ it "thingy4 does not work in a recipe" do
724
+ expect_converge {
725
+ thingy4 'blah' do; end
726
+ }.to raise_error(NoMethodError)
727
+ end
728
+
729
+ it "resource_matching_short_name returns Thingy4" do
730
+ expect(Chef::Resource.resource_matching_short_name(:thingy3)).to eq RecipeDSLSpecNamespace::Thingy3
731
+ end
732
+ end
733
+
734
+ context "and Thingy4 has resource_name :thingy3" do
735
+ before(:context) {
736
+
737
+ class RecipeDSLSpecNamespace::Thingy4 < BaseThingy
738
+ resource_name :thingy3
739
+ end
740
+
741
+ }
742
+
743
+ it "thingy3 works in a recipe and yields Thingy3 (the alphabetical one)" do
744
+ recipe = converge {
745
+ thingy3 'blah' do; end
746
+ }
747
+ expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy3
748
+ end
749
+
750
+ it "thingy4 does not work in a recipe" do
751
+ expect_converge {
752
+ thingy4 'blah' do; end
753
+ }.to raise_error(NoMethodError)
754
+ end
755
+
756
+ it "resource_matching_short_name returns Thingy4" do
757
+ expect(Chef::Resource.resource_matching_short_name(:thingy3)).to eq RecipeDSLSpecNamespace::Thingy3
758
+ end
759
+ end
760
+ end
761
+
637
762
  end
638
763
 
639
764
  context "when Thingy7 provides :thingy8" do
640
765
  before(:context) {
641
766
 
642
767
  class RecipeDSLSpecNamespace::Thingy7 < BaseThingy
768
+ resource_name :thingy7
643
769
  provides :thingy8
644
770
  end
645
771
 
@@ -661,11 +787,11 @@ describe "Recipe DSL methods" do
661
787
  expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy7
662
788
  end
663
789
 
664
- it "thingy8 works in a recipe and yields Thingy8 (the later one)" do
790
+ it "thingy8 works in a recipe and yields Thingy7 (alphabetical)" do
665
791
  recipe = converge {
666
792
  thingy8 'blah' do; end
667
793
  }
668
- expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy8
794
+ expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy7
669
795
  end
670
796
 
671
797
  it "resource_matching_short_name returns Thingy8" do
@@ -674,36 +800,36 @@ describe "Recipe DSL methods" do
674
800
  end
675
801
  end
676
802
 
677
- context "when Thingy5 provides :thingy5, :twizzle and :twizzle2" do
803
+ context "when Thingy12 provides :thingy12, :twizzle and :twizzle2" do
678
804
  before(:context) {
679
805
 
680
- class RecipeDSLSpecNamespace::Thingy5 < BaseThingy
681
- resource_name :thingy5
806
+ class RecipeDSLSpecNamespace::Thingy12 < BaseThingy
807
+ resource_name :thingy12
682
808
  provides :twizzle
683
809
  provides :twizzle2
684
810
  end
685
811
 
686
812
  }
687
813
 
688
- it "thingy5 works in a recipe and yields Thingy5" do
814
+ it "thingy12 works in a recipe and yields Thingy12" do
689
815
  expect_recipe {
690
- thingy5 'blah' do; end
816
+ thingy12 'blah' do; end
691
817
  }.to emit_no_warnings_or_errors
692
- expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy5
818
+ expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy12
693
819
  end
694
820
 
695
- it "twizzle works in a recipe and yields Thingy5" do
821
+ it "twizzle works in a recipe and yields Thingy12" do
696
822
  expect_recipe {
697
823
  twizzle 'blah' do; end
698
824
  }.to emit_no_warnings_or_errors
699
- expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy5
825
+ expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy12
700
826
  end
701
827
 
702
- it "twizzle2 works in a recipe and yields Thingy5" do
828
+ it "twizzle2 works in a recipe and yields Thingy12" do
703
829
  expect_recipe {
704
830
  twizzle2 'blah' do; end
705
831
  }.to emit_no_warnings_or_errors
706
- expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy5
832
+ expect(BaseThingy.created_resource).to eq RecipeDSLSpecNamespace::Thingy12
707
833
  end
708
834
  end
709
835
 
@@ -752,6 +878,95 @@ describe "Recipe DSL methods" do
752
878
  }.to raise_error(Chef::Exceptions::NoSuchResourceType)
753
879
  end
754
880
  end
881
+
882
+ context "when Thingy9 provides :thingy9" do
883
+ before(:context) {
884
+ class RecipeDSLSpecNamespace::Thingy9 < BaseThingy
885
+ resource_name :thingy9
886
+ end
887
+ }
888
+
889
+ it "declaring a resource providing the same :thingy9 produces a warning" do
890
+ expect(Chef::Log).to receive(:warn).with("You declared a new resource RecipeDSLSpecNamespace::Thingy9AlternateProvider for resource thingy9, but it comes alphabetically after RecipeDSLSpecNamespace::Thingy9 and has the same filters ({}), so it will not be used. Use override: true if you want to use it for thingy9.")
891
+ class RecipeDSLSpecNamespace::Thingy9AlternateProvider < BaseThingy
892
+ resource_name :thingy9
893
+ end
894
+ end
895
+ end
896
+
897
+ context "when Thingy10 provides :thingy10" do
898
+ before(:context) {
899
+ class RecipeDSLSpecNamespace::Thingy10 < BaseThingy
900
+ resource_name :thingy10
901
+ end
902
+ }
903
+
904
+ it "declaring a resource providing the same :thingy10 with override: true does not produce a warning" do
905
+ expect(Chef::Log).not_to receive(:warn)
906
+ class RecipeDSLSpecNamespace::Thingy10AlternateProvider < BaseThingy
907
+ provides :thingy10, override: true
908
+ end
909
+ end
910
+ end
911
+
912
+ context "when Thingy11 provides :thingy11" do
913
+ before(:context) {
914
+ class RecipeDSLSpecNamespace::Thingy11 < BaseThingy
915
+ resource_name :thingy10
916
+ end
917
+ }
918
+
919
+ it "declaring a resource providing the same :thingy11 with os: 'linux' does not produce a warning" do
920
+ expect(Chef::Log).not_to receive(:warn)
921
+ class RecipeDSLSpecNamespace::Thingy11AlternateProvider < BaseThingy
922
+ provides :thingy11, os: 'linux'
923
+ end
924
+ end
925
+ end
926
+ end
927
+ end
928
+
929
+ before(:all) { Namer.current_index = 0 }
930
+ before { Namer.current_index += 1 }
931
+
932
+ context "with an LWRP that declares actions" do
933
+ let(:resource_class) {
934
+ Class.new(Chef::Resource::LWRPBase) do
935
+ provides :"recipe_dsl_spec#{Namer.current_index}"
936
+ actions :create
937
+ end
938
+ }
939
+ let(:resource) {
940
+ resource_class.new("blah", run_context)
941
+ }
942
+ it "The actions are part of actions along with :nothing" do
943
+ expect(resource_class.actions).to eq [ :nothing, :create ]
944
+ end
945
+ it "The actions are part of allowed_actions along with :nothing" do
946
+ expect(resource.allowed_actions).to eq [ :nothing, :create ]
947
+ end
948
+
949
+ context "and a subclass that declares more actions" do
950
+ let(:subresource_class) {
951
+ Class.new(Chef::Resource::LWRPBase) do
952
+ provides :"recipe_dsl_spec_sub#{Namer.current_index}"
953
+ actions :delete
954
+ end
955
+ }
956
+ let(:subresource) {
957
+ subresource_class.new("subblah", run_context)
958
+ }
959
+
960
+ it "The parent class actions are not part of actions" do
961
+ expect(subresource_class.actions).to eq [ :nothing, :delete ]
962
+ end
963
+ it "The parent class actions are not part of allowed_actions" do
964
+ expect(subresource.allowed_actions).to eq [ :nothing, :delete ]
965
+ end
966
+ it "The parent class actions do not change" do
967
+ expect(resource_class.actions).to eq [ :nothing, :create ]
968
+ expect(resource.allowed_actions).to eq [ :nothing, :create ]
969
+ end
755
970
  end
756
971
  end
757
972
  end