-
Notifications
You must be signed in to change notification settings - Fork 339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't stub encrypted data bag items #249
Comments
The Chef::EncryptedDataBagItem.any_instance.stub(:load) # bad
Chef::EncryptedDataBagItem.stub(:load) # good Attempt 2 failed because 1. that's the old syntax for stubbing a stub_data_bag('users').and_return(['bill'])
stub_data_bag_item('users', 'bill').and_return({ ... }) |
Thanks for the quick response! # Set node attributes and converge
chef_run.node.set['s3cmd']['key'] = "<the-actual-secret-key>"
chef_run.converge(described_recipe)
stub_data_bag('credentials').and_return({id: 'aws'})
stub_data_bag_item('credentials', 'aws').and_return({"access_key_id" => "abc123", "secrect_access_key" => "secret", "gpg_passphrase" => "pass"}) This renders the following error:
Any clues? |
@esset09 you're using an describe 'mycookbook::default' do
let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) }
before do
Chef::EncryptedDataBagItem.stub(:load).with('credentials', 'aws').and_return({
'access_key_id' => 'abc123',
'secrect_access_key' => 'secret',
'gpg_passphrase' => 'pass'
})
end
it 'does whatever' do
expect(chef_run).to do_something('thing')
end
end |
Ah, yes, that's it. Actually, I had to do: Chef::EncryptedDataBagItem.stub(:load).with('credentials', 'aws', 'secret').and_return({...})
...
chef_run.node.set['s3cmd']['key'] = "secret" Great success! Thanks a lot! |
@sethvargo this was vastly helpful in my stubbing out an encrypted data bag, any chance this could end up in the README? |
I can't figure out how to stub encrypted data bag items. I've tried a number of various approaches, without success.
I'm getting different errors with different approaches:
Isn't there support for this yet? Or am I just not understanding how to use it?
Thanks.
– – –
This is what my actual impl looks like in
mycookbook
(which obviously has another name in real life):recipes/default.rb:
spec/default_spec.rb:
The text was updated successfully, but these errors were encountered: