diff options
author | Bryan McLellan <btm@chef.io> | 2015-12-04 11:23:10 -0500 |
---|---|---|
committer | Bryan McLellan <btm@chef.io> | 2015-12-04 11:23:10 -0500 |
commit | 9ecd48c603a5238ddb45ca74c306e546b4f5ccd9 (patch) | |
tree | 1c998167230a0dc5a3e5e40b9f545e1502a53eb0 | |
parent | 3c18cd94ec153b73441ef3e3f4bd3c82a7f24587 (diff) | |
download | chef-9ecd48c603a5238ddb45ca74c306e546b4f5ccd9.tar.gz |
Chef::DataBag.load should raise in solo mode if we have no data bag pathbtm/raise-without-databag-path
Chef::Config[:data_bag_path] is required for data bag use in solo mode
-rw-r--r-- | lib/chef/data_bag.rb | 1 | ||||
-rw-r--r-- | spec/unit/data_bag_spec.rb | 11 |
2 files changed, 12 insertions, 0 deletions
diff --git a/lib/chef/data_bag.rb b/lib/chef/data_bag.rb index 401ba6f63f..e07d5312ca 100644 --- a/lib/chef/data_bag.rb +++ b/lib/chef/data_bag.rb @@ -112,6 +112,7 @@ class Chef # Load a Data Bag by name via either the RESTful API or local data_bag_path if run in solo mode def self.load(name) if Chef::Config[:solo] + raise Chef::Exceptions::InvalidDataBagPath, "Chef::Config[:data_bag_path] is required for data bag use in solo mode" unless Chef::Config[:data_bag_path] paths = Array(Chef::Config[:data_bag_path]) data_bag = {} paths.each do |path| diff --git a/spec/unit/data_bag_spec.rb b/spec/unit/data_bag_spec.rb index 13b835d120..cab11c15b6 100644 --- a/spec/unit/data_bag_spec.rb +++ b/spec/unit/data_bag_spec.rb @@ -255,6 +255,17 @@ describe Chef::DataBag do describe "data bag with array path" do it_should_behave_like "data bag in solo mode", ["/var/chef/data_bags", "/var/chef/data_bags_2"] end + + describe "data bag with no path" do + before do + Chef::Config[:solo] = true + Chef::Config[:data_bag_path] = nil + end + + it "raises an exception" do + expect { Chef::DataBag.load('foo') }.to raise_error(Chef::Exceptions::InvalidDataBagPath) + end + end end end |