diff options
author | Noah Kantrowitz <noah@coderanger.net> | 2016-03-02 17:50:27 -0800 |
---|---|---|
committer | Noah Kantrowitz <noah@coderanger.net> | 2016-03-02 17:50:27 -0800 |
commit | 8f5f95b90db1b9f5fc4a30a9e54ebfd81cce5177 (patch) | |
tree | 6de211e312bfa49eda72faeb641a4d347a2cd441 | |
parent | a4d98365c1d68d7a24fba62783538951d2bbd2e0 (diff) | |
download | chef-8f5f95b90db1b9f5fc4a30a9e54ebfd81cce5177.tar.gz |
Clearer exception for loading non-existent data bag items in solo mode.
-rw-r--r-- | lib/chef/data_bag_item.rb | 1 | ||||
-rw-r--r-- | spec/unit/data_bag_item_spec.rb | 5 |
2 files changed, 6 insertions, 0 deletions
diff --git a/lib/chef/data_bag_item.rb b/lib/chef/data_bag_item.rb index 6ac863a47d..4d6e33ce1f 100644 --- a/lib/chef/data_bag_item.rb +++ b/lib/chef/data_bag_item.rb @@ -150,6 +150,7 @@ class Chef def self.load(data_bag, name) if Chef::Config[:solo] bag = Chef::DataBag.load(data_bag) + raise Exceptions::InvalidDataBagItemID, "Item #{name} not found in data bag #{data_bag}. Other items found: #{bag.keys.join(", ")}" unless bag.include?(name) item = bag[name] else item = Chef::ServerAPI.new(Chef::Config[:chef_server_url]).get("data/#{data_bag}/#{name}") diff --git a/spec/unit/data_bag_item_spec.rb b/spec/unit/data_bag_item_spec.rb index 7f7d2b3013..c5a4403283 100644 --- a/spec/unit/data_bag_item_spec.rb +++ b/spec/unit/data_bag_item_spec.rb @@ -325,6 +325,11 @@ describe Chef::DataBagItem do expect(item).to be_a_kind_of(Chef::DataBagItem) expect(item).to eq(data_bag_item) end + + it "raises an exception for unknown items" do + expect(Chef::DataBag).to receive(:load).with("users").and_return({ "charlie" => data_bag_item.to_hash }) + expect { Chef::DataBagItem.load("users", "wonka") }.to raise_error Chef::Exceptions::InvalidDataBagItemID + end end end end |