diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2017-03-16 16:10:18 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-16 16:10:18 -0700 |
commit | f76bbb6f5f6a67199df9d302ef20b647e208ab1e (patch) | |
tree | 338f8786067c505812747bc0ee9e2ff5962c16d4 | |
parent | f3e87f59f66072cb86bce67d80ac2047041bd7be (diff) | |
parent | 619a3d40eb6e0aa1627f5cafbc25245a7eef447f (diff) | |
download | chef-f76bbb6f5f6a67199df9d302ef20b647e208ab1e.tar.gz |
Merge pull request #5911 from chef/lcg/debub-value-arrays
fix node#debug_value access through arrays
-rw-r--r-- | lib/chef/node/attribute.rb | 12 | ||||
-rw-r--r-- | spec/unit/node/attribute_spec.rb | 23 |
2 files changed, 24 insertions, 11 deletions
diff --git a/lib/chef/node/attribute.rb b/lib/chef/node/attribute.rb index 761694e010..57d1b0a4d3 100644 --- a/lib/chef/node/attribute.rb +++ b/lib/chef/node/attribute.rb @@ -216,16 +216,12 @@ class Chef # that precedence level, +value+ will be the symbol +:not_present+. def debug_value(*args) COMPONENTS.map do |component| - ivar = instance_variable_get(component) - value = args.inject(ivar) do |so_far, key| - if so_far == :not_present - :not_present - elsif so_far.has_key?(key) - so_far[key] - else + value = + begin + instance_variable_get(component).read!(*args) + rescue :not_present end - end [component.to_s.sub(/^@/, ""), value] end end diff --git a/spec/unit/node/attribute_spec.rb b/spec/unit/node/attribute_spec.rb index 3dd0d0f650..cf8d4d4a4f 100644 --- a/spec/unit/node/attribute_spec.rb +++ b/spec/unit/node/attribute_spec.rb @@ -208,7 +208,7 @@ describe Chef::Node::Attribute do end describe "when debugging attributes" do - before do + it "gives the value at each level of precedence for a path spec" do @attributes.default[:foo][:bar] = "default" @attributes.env_default[:foo][:bar] = "env_default" @attributes.role_default[:foo][:bar] = "role_default" @@ -219,9 +219,7 @@ describe Chef::Node::Attribute do @attributes.env_override[:foo][:bar] = "env_override" @attributes.force_override[:foo][:bar] = "force_override" @attributes.automatic[:foo][:bar] = "automatic" - end - it "gives the value at each level of precedence for a path spec" do expected = [ %w{default default}, %w{env_default env_default}, @@ -236,6 +234,25 @@ describe Chef::Node::Attribute do ] expect(@attributes.debug_value(:foo, :bar)).to eq(expected) end + + it "works through arrays" do + @attributes.default["foo"] = [ { "bar" => "baz" } ] + + expect(@attributes.debug_value(:foo, 0)).to eq( + [ + ["default", { "bar" => "baz" }], + ["env_default", :not_present], + ["role_default", :not_present], + ["force_default", :not_present], + ["normal", :not_present], + ["override", :not_present], + ["role_override", :not_present], + ["env_override", :not_present], + ["force_override", :not_present], + ["automatic", :not_present], + ] + ) + end end describe "when fetching values based on precedence" do |