Unit testing 用于测试配方中数据包的chefspec
我的食谱中有这段代码,现在我想编写一个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
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