chef / chef-vault-testfixtures

provides an RSpec shared context for testing Chef cookbooks that use chef-vault
Apache License 2.0
7 stars 10 forks source link

Allow configurable data bags paths #13

Closed mhenrixon closed 6 years ago

mhenrixon commented 9 years ago

I don't want to move my files around to be able to stub stuff so decided to make the directory configurable.

jf647 commented 9 years ago

In case that conflicts with something chefspec does in the future, can we change the setting to something like 'chef_vault_data_bags_path' instead?

mhenrixon commented 9 years ago

Fixed! I also added a failing test for what I would consider a missing feature. It seems something isn't working like it should. I created a new recipe to test the ['id'] and the custom path but it is not loading my json file.

jf647 commented 9 years ago

In your test1_vault_spec.rb file, you aren't loading the data bag using your helper (compare the loading that's in test1_default_spec.rb).

Also, the data bag loading helper always looks in test/integration/data bags.

I got your fork to test clean by declaring the chef_run like this:

  let(:chef_run) do
    ChefSpec::ServerRunner.new do |_, server|
      server.create_data_bag(
        'lol', 'rofl' => parse_data_bag(
          'lol/rofl.json', '../../test/fixtures/data_bags'
        )
      )
    end.converge(described_recipe)
  end

and enhancing the data bag loading helper like this:

module DataBagHelper
  def parse_data_bag(fname, dname = '../../test/integration/data_bags')
    data_bags_path = File.expand_path(
      File.join(File.dirname(__FILE__), dname)
    )
    JSON.parse(File.read("#{data_bags_path}/#{fname}"))
  end
end

Though I'm not sure that's the cleanest way to achieve what you were going for.

mhenrixon commented 9 years ago

I am not interested in using the ServerRunner due to performance.

jf647 commented 9 years ago

OK, so just update the PR once you have something that tests clean with SoloRunner.

mhenrixon commented 9 years ago

This is what I have to resort to in my cookbook using this:

cs_app = get_databag_item('db_users', 'casinosaga')
allow(ChefVault::Item).to receive(:load).and_call_original # like mentioned in #11
allow(ChefVault::Item).to receive(:load).with('db_users', 'casinosaga').and_return(cs_app)

certs = get_databag_item('certificates', 'casinosaga')
allow(ChefVault::Item).to receive(:load).with('certificates', 'casinosaga').and_return(certs)

Not sure why I have to stub specific loads like this but it works at least. Have any suggestions for where to go from here?

4-20ma commented 8 years ago

I would also like this feature so I can keep my test data bags with my unit and other integration tests. Is this still a viable PR?