Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing 用于测试配方中数据包的chefspec_Unit Testing_Chef Infra_Chef Recipe_Devops_Chefspec - Fatal编程技术网

Unit testing 用于测试配方中数据包的chefspec

Unit testing 用于测试配方中数据包的chefspec,unit-testing,chef-infra,chef-recipe,devops,chefspec,Unit Testing,Chef Infra,Chef Recipe,Devops,Chefspec,我的食谱中有这段代码,现在我想编写一个chefspec,在节点上执行代码之前对其进行测试 我在谷歌上搜索了一些样本规范配方,但找不到任何与数据包相关的内容 userlist = data_bag('systemuser') userlist.each do | identifier| users = data_bag_item('systemuser', identifier) user(users['id']) do comment users['comment'] e

我的食谱中有这段代码,现在我想编写一个chefspec,在节点上执行代码之前对其进行测试

我在谷歌上搜索了一些样本规范配方,但找不到任何与数据包相关的内容

userlist = data_bag('systemuser')

userlist.each do | identifier|
  users = data_bag_item('systemuser', identifier)

  user(users['id']) do
    comment users['comment']
  end
end

我需要一些关于如何编写测试上述代码的规范的帮助

如果没有您的数据包样本,这里有一个基本模型供您进一步开发

require 'chefspec'

describe 'cookbookname::recipename' do
  let(:chef_run) { ChefSpec::SoloRunner.converge(described_recipe) }

  context 'when the data_bag is not stubbed' do
    it 'raises an exception' do
      expect {
        chef_run
      }.to raise_error(ChefSpec::Error::DataBagNotStubbed)
    end
  end
  context 'stub array test' do
     it 'does not raise an exception' do
       stub_data_bag('systemuser').and_return([
          { id: 1, comment: 'delicious' },
          { id: 2, comment: 'also good' }
         ])
       expect { chef_run }.to_not raise_error
     end
  end

end