在Chefspec中对Chef-Vault进行存根抛出异常

时间:2019-06-20 16:46:26

标签: ruby rspec chef chefspec chef-vault

我正在尝试从RSpec中的chef_vault_item包中对方法chef-vault进行存根,但是我遇到了一个愚蠢的HTTPServerException: 404 "Not Found,我正在关注这个article 但这并不能解释我收到的错误。我是Rspec测试厨师食谱整体上的新手,所以请帮助我在这里找到问题:

  

recipes / default.rb

...
include_recipe 'chef-vault'
secrets = chef_vault_item("secrets", node.chef_environment)
...
  

spec / spec_helper.rb

require 'chefspec'
require 'chef-vault'
require 'chefspec/berkshelf'
  

spec / unit / recipes / default_spec.rb

  require 'spec_helper'

  describe 'CAMM7_NewRelic_Install::default' do

    context 'When all attributes are default, on Oracle 7.6' do
     before do
      allow(ChefVault).to receive(:chef_vault_item).and_return(secret_data)
      #allow(Chef::DataBag).to receive(:load).with(anything).and_return('_default_keys' => {})
      #allow(ChefVault::Item).to receive(:load).with(anything, anything).and_return(secret_data)
     end

    let(:secret_data) do
      {
        'id' => '_default',
        "d-oracle-7" => {
          "newRelic" => {
              "licenseKey" => "blah-blah-blah"
          }
        }
      } 
    end

    let(:chef_run) do
      runner = ChefSpec::ServerRunner.new(platform: 'oracle', version: '7.6') do |node|
      end
      runner.converge(described_recipe)
    end


    it 'converges successfully' do 
      expect { chef_run }.to_not raise_error 
    end
  end
end

我得到的错误是:

Failures:

1) CAMM7_NewRelic_Install::default When all attributes are default, on Oracle 7.6 converges successfully
 Failure/Error: expect { chef_run }.to_not raise_error

   expected no Exception, got #<Net::HTTPServerException: 404 "Not Found "> with backtrace:
     # C:/Users/ns069952/AppData/Local/Temp/chefspec20190620-20352-wfom2afile_cache_path/cookbooks/chef-vault/libraries/helpers.rb:38:in `chef_vault_item'
     # C:/Users/ns069952/AppData/Local/Temp/chefspec20190620-20352-wfom2afile_cache_path/cookbooks/CAMM7_NewRelic_Install/recipes/default.rb:91:in `from_file'
     # ./spec/unit/recipes/default_spec.rb:41:in `block (3 levels) in <top (required)>'
     # ./spec/unit/recipes/default_spec.rb:47:in `block (4 levels) in <top (required)>'
     # ./spec/unit/recipes/default_spec.rb:47:in `block (3 levels) in <top (required)>'
 # ./spec/unit/recipes/default_spec.rb:47:in `block (3 levels) in <top (required)>'

Finished in 11.97 seconds (files took 6.51 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/unit/recipes/default_spec.rb:45 # CAMM7_NewRelic_Install::default When all attributes are default, on Oracle 7.6 converges successfully

错误从secrets = chef_vault_item("secrets", node.chef_environment)内的行recipes/default.rb抛出

0 个答案:

没有答案