summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2016-10-31 15:26:04 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2016-10-31 15:26:04 -0700
commitedede76c46eb388b74292a20b4701a1b9b88c535 (patch)
tree0e95cf52a5c2ab094edc05e126640cb103587716 /spec
parentcbd6420c47bdefb39d676e1c054d7da041d102ce (diff)
downloadchef-edede76c46eb388b74292a20b4701a1b9b88c535.tar.gz
add some unit testing of new node APIslcg/attribute-setting-event
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/node/attribute_spec.rb47
1 files changed, 46 insertions, 1 deletions
diff --git a/spec/unit/node/attribute_spec.rb b/spec/unit/node/attribute_spec.rb
index 00081a9fd9..a3e62ff939 100644
--- a/spec/unit/node/attribute_spec.rb
+++ b/spec/unit/node/attribute_spec.rb
@@ -21,7 +21,11 @@ require "spec_helper"
require "chef/node/attribute"
describe Chef::Node::Attribute do
+ let(:events) { instance_double(Chef::EventDispatch::Dispatcher) }
+ let(:run_context) { instance_double(Chef::RunContext, :events => events) }
+ let(:node) { instance_double(Chef::Node, :run_context => run_context) }
before(:each) do
+ allow(events).to receive(:attribute_changed)
@attribute_hash =
{ "dmi" => {},
"command" => { "ps" => "ps -ef" },
@@ -166,7 +170,7 @@ describe Chef::Node::Attribute do
},
}
@automatic_hash = { "week" => "friday" }
- @attributes = Chef::Node::Attribute.new(@attribute_hash, @default_hash, @override_hash, @automatic_hash)
+ @attributes = Chef::Node::Attribute.new(@attribute_hash, @default_hash, @override_hash, @automatic_hash, node)
end
describe "initialize" do
@@ -1196,4 +1200,45 @@ describe Chef::Node::Attribute do
expect(@attributes["foo"]["baz"]["bar"]).to be true
end
end
+
+ describe "node state" do
+ it "sets __root__ correctly" do
+ @attributes.default["foo"]["bar"]["baz"] = "quux"
+ expect(@attributes["foo"].__root__).to eql(@attributes)
+ expect(@attributes["foo"]["bar"].__root__).to eql(@attributes)
+ expect(@attributes.default["foo"].__root__).to eql(@attributes)
+ expect(@attributes.default["foo"]["bar"].__root__).to eql(@attributes)
+ end
+
+ it "sets __node__ correctly" do
+ @attributes.default["foo"]["bar"]["baz"] = "quux"
+ expect(@attributes["foo"].__node__).to eql(node)
+ expect(@attributes["foo"]["bar"].__node__).to eql(node)
+ expect(@attributes.default["foo"].__node__).to eql(node)
+ expect(@attributes.default["foo"]["bar"].__node__).to eql(node)
+ end
+
+ it "sets __path__ correctly" do
+ @attributes.default["foo"]["bar"]["baz"] = "quux"
+ expect(@attributes["foo"].__path__).to eql(["foo"])
+ expect(@attributes["foo"]["bar"].__path__).to eql(%w{foo bar})
+ expect(@attributes.default["foo"].__path__).to eql(["foo"])
+ expect(@attributes.default["foo"]["bar"].__path__).to eql(%w{foo bar})
+ end
+
+ it "sets __precedence__ correctly" do
+ @attributes.default["foo"]["bar"]["baz"] = "quux"
+ expect(@attributes["foo"].__precedence__).to eql(:merged)
+ expect(@attributes["foo"]["bar"].__precedence__).to eql(:merged)
+ expect(@attributes.default["foo"].__precedence__).to eql(:default)
+ expect(@attributes.default["foo"]["bar"].__precedence__).to eql(:default)
+ end
+
+ it "notifies on attribute changes" do
+ expect(events).to receive(:attribute_changed).with(:default, ["foo"], {})
+ expect(events).to receive(:attribute_changed).with(:default, %w{foo bar}, {})
+ expect(events).to receive(:attribute_changed).with(:default, %w{foo bar baz}, "quux")
+ @attributes.default["foo"]["bar"]["baz"] = "quux"
+ end
+ end
end