Sha256: 5b9b36fa341bbddfcad964bdbeed2360ea2153a9f97ea47d2689e22c8ff27a09

Contents?: true

Size: 1.56 KB

Versions: 1

Compression:

Stored size: 1.56 KB

Contents

require 'spec_helper'

describe Chef::Sugar::DataBag do
  describe '#encrypted_data_bag_item' do
    before { Chef::EncryptedDataBagItem.stub(:load) }

    it 'loads the encrypted data bag item' do
      expect(Chef::EncryptedDataBagItem).to receive(:load)
        .with('accounts', 'github')

      described_class.encrypted_data_bag_item('accounts', 'github')
    end
  end

  describe '#encrypted_data_bag_item_for_environment' do
    let(:node) { double(:node, chef_environment: 'production') }

    context 'when the environment exists' do
      it 'loads the data from the environment' do
        Chef::EncryptedDataBagItem.stub(:load).and_return(
          'production' => {
            'username' => 'sethvargo',
            'password' => 'bacon',
          }
        )

        expect(described_class.encrypted_data_bag_item_for_environment(node, 'accounts', 'github')).to eq(
          'password' => 'bacon',
          'username' => 'sethvargo',
        )
      end
    end

    context 'when the environment does not exist' do
      it 'loads the data from the default bucket' do
        Chef::EncryptedDataBagItem.stub(:load).and_return(
          'staging' => {
            'username' => 'sethvargo',
            'password' => 'bacon',
          },
          'default' => {
            'username' => 'schisamo',
            'password' => 'ham',
          }
        )

        expect(described_class.encrypted_data_bag_item_for_environment(node, 'accounts', 'github')).to eq(
          'password' => 'ham',
          'username' => 'schisamo',
        )
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
chef-sugar-1.1.0 spec/unit/chef/extensions/data_bag_spec.rb