summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2017-03-16 14:40:40 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2017-03-16 14:40:40 -0700
commit619a3d40eb6e0aa1627f5cafbc25245a7eef447f (patch)
tree0b121794fbb6c16e0c908f945a6649abc2671d8d
parent1f23881a95d1dfa63158c7c35d3f8723df97a758 (diff)
downloadchef-lcg/debub-value-arrays.tar.gz
fix node#debug_value access through arrayslcg/debub-value-arrays
nod to @jaymzh for finding this one. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/node/attribute.rb12
-rw-r--r--spec/unit/node/attribute_spec.rb23
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