无法为chefspec存根partial_search

时间:2014-05-29 15:35:29

标签: search rspec chef chefspec

我正在编写一本菜单,该菜谱运行部分搜索以在其他节点上查找属性。我的chefspec测试失败,错误为ERROR: Connection refused connecting to localhost:443。搜索实例化如下:

describe 'my_recipe::default' do
  let(:test1_node) do
    stub_node('test1.com', platform: 'redhat', version: '6.3') do |node|
      node.set['my_recipe']['id'] = 101
      node.set['chef_environment'] = 'production'
    end
  end

  let(:test2_node) do
    stub_node('test2.com', platform: 'redhat', version: '6.3') do |node|
      node.set['my_recipe']['id'] = 102
      node.set['chef_environment'] = 'production'
    end
  end

  before do
    stub_search("node", "my_recipe:* AND chef_environment:production").and_return([])
  end
  let(:chef_run) do
    ChefSpec::Runner.new do |node|
      env = Chef::Environment.new
      env.name 'production'

      node.stub(:chef_environment).and_return(env.name)
      Chef::Environment.stub(:load).and_return(env)
    end.converge(described_recipe)
  end
  it 'updates the file' do
    stub_search("node", "my_recipe:* AND chef_environment:production").and_return([test1_node,test2_node])
    expect(chef_run).to create_template(/conf/my_recipe.cfg")
  end
end

我是不是错误地抄写了这个?

1 个答案:

答案 0 :(得分:1)

stub_search用于存根Chef Search。部分搜索由cookbook支持,因此不属于Chef核心。部分搜索使用不同的API端点,并使用POST而不是GET作为协议。

您需要将Chef的API调用存根到部分搜索。 stub_search无效。

相关问题