summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/node_map.rb1
-rw-r--r--lib/chef/resource.rb6
-rw-r--r--spec/unit/resource_spec.rb26
3 files changed, 31 insertions, 2 deletions
diff --git a/lib/chef/node_map.rb b/lib/chef/node_map.rb
index 9c3d223181..a4891234f5 100644
--- a/lib/chef/node_map.rb
+++ b/lib/chef/node_map.rb
@@ -66,6 +66,7 @@ EOH
# override from cookbooks is allowed.
# @param __core_override__ [Boolean] Advanced-mode override to add to a key
# even in locked mode.
+ # @param chef_version [String] version constraint to match against the running Chef::VERSION
#
# @yield [node] Arbitrary node filter as a block which takes a node argument
#
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index f65af0c7eb..1440b2eb61 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -1320,8 +1320,10 @@ class Chef
# Once we no longer care about supporting chef < 14.4 then we can deprecate
# this API.
#
- def self.chef_version_for_provides(arg)
- @chef_version_for_provides = arg
+ # @param arg [String] version constrant to match against (e.g. "> 14")
+ #
+ def self.chef_version_for_provides(constraint)
+ @chef_version_for_provides = constraint
end
#
diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb
index a4f64e11e1..921ca6d33e 100644
--- a/spec/unit/resource_spec.rb
+++ b/spec/unit/resource_spec.rb
@@ -966,6 +966,32 @@ describe Chef::Resource do
end
end
+ describe "chef_version constraints and the platform map" do
+ let(:klz3) { Class.new(Chef::Resource) }
+
+ it "doesn't wire up the provides when chef_version is < 1" do
+ klz3.provides :bulbasaur, chef_version: "< 1.0" # this should be false
+ expect { Chef::Resource.resource_for_node(:bulbasaur, node) }.to raise_error(Chef::Exceptions::NoSuchResourceType)
+ end
+
+ it "wires up the provides when chef_version is > 1" do
+ klz3.provides :bulbasaur, chef_version: "> 1.0" # this should be true
+ expect(Chef::Resource.resource_for_node(:bulbasaur, node)).to eql(klz3)
+ end
+
+ it "wires up the default when chef_version is < 1" do
+ klz3.chef_version_for_provides("< 1.0") # this should be false
+ klz3.provides :bulbasaur
+ expect { Chef::Resource.resource_for_node(:bulbasaur, node) }.to raise_error(Chef::Exceptions::NoSuchResourceType)
+ end
+
+ it "wires up the default when chef_version is > 1" do
+ klz3.chef_version_for_provides("> 1.0") # this should be true
+ klz3.provides :bulbasaur
+ expect(Chef::Resource.resource_for_node(:bulbasaur, node)).to eql(klz3)
+ end
+ end
+
end
describe "when creating notifications" do