diff options
author | Noah Kantrowitz <noah@coderanger.net> | 2018-05-04 17:40:58 -0700 |
---|---|---|
committer | Noah Kantrowitz <noah@coderanger.net> | 2018-06-05 20:25:11 -0700 |
commit | 507da22ccbd821a437ca33a7d4fb1eb42966c471 (patch) | |
tree | fce27ebae91a21191e665ecd85b8f753d45f73f4 | |
parent | c88877cecb0a24a7a85c6cb2015ffd2b39c10ecd (diff) | |
download | chef-507da22ccbd821a437ca33a7d4fb1eb42966c471.tar.gz |
Some tests for locked mode.
Signed-off-by: Noah Kantrowitz <noah@coderanger.net>
-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 |