diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2018-11-07 14:06:07 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2018-11-09 14:17:09 -0800 |
commit | f827907b83b3c4a55200ebdf2f89882bc1f3736a (patch) | |
tree | 11a1b38b3510ce9a01207e66411dcf308886e1d8 /spec/unit/node | |
parent | 156e91bff63f275884ff6ddcb70ab49a05c7270d (diff) | |
download | chef-f827907b83b3c4a55200ebdf2f89882bc1f3736a.tar.gz |
Chef-15: add nillability to attribute deep merging
Changes to consistently uses the "NIL" object internally to mean "not present"
instead of abusing nil for that purpose.
So now "nil means nil" and we can deep merge that so it will effectively
override lower precedence levels if you write a nil.
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'spec/unit/node')
-rw-r--r-- | spec/unit/node/attribute_spec.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/spec/unit/node/attribute_spec.rb b/spec/unit/node/attribute_spec.rb index 36827215f0..c6fdf1e1c2 100644 --- a/spec/unit/node/attribute_spec.rb +++ b/spec/unit/node/attribute_spec.rb @@ -1273,4 +1273,34 @@ describe Chef::Node::Attribute do expect { @attributes["foo"]["bar"][0] << "buzz" }.to raise_error(RuntimeError, "can't modify frozen String") end end + + describe "deep merging with nils" do + it "nils when deep merging between default levels knocks out values" do + @attributes.default["foo"] = "bar" + expect(@attributes["foo"]).to eql("bar") + @attributes.force_default["foo"] = nil + expect(@attributes["foo"]).to be nil + end + + it "nils when deep merging between override levels knocks out values" do + @attributes.override["foo"] = "bar" + expect(@attributes["foo"]).to eql("bar") + @attributes.force_override["foo"] = nil + expect(@attributes["foo"]).to be nil + end + + it "nils when deep merging between default+override levels knocks out values" do + @attributes.default["foo"] = "bar" + expect(@attributes["foo"]).to eql("bar") + @attributes.override["foo"] = nil + expect(@attributes["foo"]).to be nil + end + + it "nils when deep merging between normal+automatic levels knocks out values" do + @attributes.normal["foo"] = "bar" + expect(@attributes["foo"]).to eql("bar") + @attributes.automatic["foo"] = nil + expect(@attributes["foo"]).to be nil + end + end end |