summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/data_bag.rb1
-rw-r--r--spec/unit/data_bag_spec.rb11
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