diff options
author | Claire McQuin <claire@getchef.com> | 2014-08-21 09:47:03 -0700 |
---|---|---|
committer | Claire McQuin <claire@getchef.com> | 2014-08-22 11:59:32 -0700 |
commit | 6be5678fe7e0a5c1cf5a96ec096cf7e2d7bef194 (patch) | |
tree | a4b5c71da3091b1ec457266b84e19266d1d04b67 /spec/unit | |
parent | ff4109b12508a74ae99bf4fc0e1e0c4a4f9a9cc5 (diff) | |
download | chef-6be5678fe7e0a5c1cf5a96ec096cf7e2d7bef194.tar.gz |
Add error logging on failure to load secret file.
Diffstat (limited to 'spec/unit')
-rw-r--r-- | spec/unit/dsl/data_query_spec.rb | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/spec/unit/dsl/data_query_spec.rb b/spec/unit/dsl/data_query_spec.rb index 675b10d34f..8a985437b7 100644 --- a/spec/unit/dsl/data_query_spec.rb +++ b/spec/unit/dsl/data_query_spec.rb @@ -175,23 +175,31 @@ describe Chef::DSL::DataQuery do end end - context "when Chef::Config[:encrypted_data_bag_secret] is not configured" do - let(:path) { nil } - + shared_examples_for "no secret file" do it "should fail to load the data bag item" do - expect{ language.data_bag_item(bag_name, item_name) }.to raise_error(ArgumentError, /No secret specified and no secret found/) + expect( Chef::Log ).to receive(:error).with(/Failed to load secret for encrypted data bag item/) + expect( Chef::Log ).to receive(:error).with(/Failed to load data bag item/) + expect{ language.data_bag_item(bag_name, item_name) }.to raise_error(error_type, error_message) end end - context "when Chef::Config[:encrypted_data_bag_secret] does not exist" do - let(:path) { "/tmp/my_secret" } - - before do - expect( File ).to receive(:exist?).with(path).and_return(false) + context "when Chef::Config[:encrypted_data_bag_secret] is not configured" do + include_examples "no secret file" do + let(:path) { nil } + let(:error_type) { ArgumentError } + let(:error_message) { /No secret specified and no secret found/ } end + end - it "should fail to load the data bag item" do - expect{ language.data_bag_item(bag_name, item_name) }.to raise_error(Errno::ENOENT, /file not found/) + context "when Chef::Config[:encrypted_data_bag_secret] does not exist" do + include_examples "no secret file" do + before do + expect( File ).to receive(:exist?).with(path).and_return(false) + end + + let(:path) { "/tmp/my_secret" } + let(:error_type) { Errno::ENOENT } + let(:error_message) { /file not found/ } end end end |