diff options
author | Noah Kantrowitz <noah@coderanger.net> | 2016-03-03 09:23:42 -0800 |
---|---|---|
committer | Noah Kantrowitz <noah@coderanger.net> | 2016-03-03 09:23:42 -0800 |
commit | 5979a39fbbb3640283eb81c8bce68ac2b509783c (patch) | |
tree | 1a890b04d2f21e8145eea60f753b2e433a6c79fe | |
parent | 383e681013bdd188f208753f9be60b4b9580aa52 (diff) | |
parent | 8f5f95b90db1b9f5fc4a30a9e54ebfd81cce5177 (diff) | |
download | chef-5979a39fbbb3640283eb81c8bce68ac2b509783c.tar.gz |
Merge pull request #4655 from coderanger/solobag
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 |