diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/node_map_spec.rb | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/spec/unit/node_map_spec.rb b/spec/unit/node_map_spec.rb index 24f3bebe2a..d25bf871fe 100644 --- a/spec/unit/node_map_spec.rb +++ b/spec/unit/node_map_spec.rb @@ -22,6 +22,12 @@ require "chef/node_map" class Foo; end class Bar; end +class FooResource < Chef::Resource; end +class BarResource < Chef::Resource; end + +class FooProvider < Chef::Provider; end +class BarProvider < Chef::Provider; end + describe Chef::NodeMap do let(:node_map) { Chef::NodeMap.new } @@ -204,4 +210,58 @@ describe Chef::NodeMap do end end + describe "locked mode" do + context "while unlocked" do + it "allows setting the same key twice" do + expect(Chef).to_not receive(:log_deprecation) + node_map.set(:foo, FooResource) + node_map.set(:foo, BarResource) + expect(node_map.get(node, :foo)).to eql(BarResource) + end + end + + context "while locked" do + # Uncomment the commented `expect`s in 15.0. + it "rejects setting the same key twice" do + expect(Chef).to receive(:log_deprecation).with("Trying to register resource foo on top of existing Chef core resource. Check if a new version of the cookbook is available.") + node_map.set(:foo, FooResource) + node_map.lock! + node_map.set(:foo, BarResource) + # expect(node_map.get(node, :foo)).to eql(FooResource) + end + + it "allows setting the same key twice when the first has allow_cookbook_override" do + expect(Chef).to_not receive(:log_deprecation) + node_map.set(:foo, FooResource, allow_cookbook_override: true) + node_map.lock! + node_map.set(:foo, BarResource) + expect(node_map.get(node, :foo)).to eql(BarResource) + end + + it "allows setting the same key twice when the first has allow_cookbook_override with a future version" do + expect(Chef).to_not receive(:log_deprecation) + node_map.set(:foo, FooResource, allow_cookbook_override: "< 100") + node_map.lock! + node_map.set(:foo, BarResource) + expect(node_map.get(node, :foo)).to eql(BarResource) + end + + it "rejects setting the same key twice when the first has allow_cookbook_override with a past version" do + expect(Chef).to receive(:log_deprecation).with("Trying to register resource foo on top of existing Chef core resource. Check if a new version of the cookbook is available.") + node_map.set(:foo, FooResource, allow_cookbook_override: "< 1") + node_map.lock! + node_map.set(:foo, BarResource) + # expect(node_map.get(node, :foo)).to eql(FooResource) + end + + it "allows setting the same key twice when the second has __core_override__" do + expect(Chef).to_not receive(:log_deprecation) + node_map.set(:foo, FooResource) + node_map.lock! + node_map.set(:foo, BarResource, __core_override__: true) + expect(node_map.get(node, :foo)).to eql(BarResource) + end + end + end + end |