我正在尝试使用 chefspec 运行单元测试。我在我的食谱中添加了数据包。没有数据包,chefspec 测试运行良好。添加 databags chefspec 后显示以下错误:
1) database::prerequisites installs a package
Failure/Error: let(:chef_run) { ChefSpec::ServerRunner.new(platform: 'oracle', version: '7.2').converge(described_recipe) }
Net::HTTPServerException:
404 "Not Found "
# /tmp/chefspec20170616-8187-olziw2file_cache_path/cookbooks/database/recipes/prerequisites.rb:9:in `from_file'
# ./prerequisites_spec.rb:4:in `block (2 levels) in <top (required)>'
# ./prerequisites_spec.rb:25:in `block (2 levels) in <top (required)>'
我不知道如何在chefspec 中处理数据包。当我在工作站中使用厨师客户端执行食谱时,它工作正常。但是chefspec测试失败了。
配方规格文件:
require 'chefspec'
describe 'database::prerequisites' do
let(:chef_run) { ChefSpec::ServerRunner.new(platform: 'oracle', version: '7.2').converge(described_recipe) }
before(:each) do
stub_command("cat /etc/oracle-release | grep 7.*").and_return(true)
end
before(:each) do
stub_command("cat /etc/oracle-release | grep 6.*").and_return(true)
end
before(:each) do
stub_command("cat /etc/selinux/config | grep SELINUX=disabled").and_return(true)
end
before(:each) do
stub_command("sestatus | grep enabled").and_return(true)
end
it 'installs a package ' do
expect(chef_run).to install_package('oracle-rdbms-server-12cR1-preinstall')
expect(chef_run).to install_package('net-tools')
expect(chef_run).to install_package('xorg-x11-apps')
end
it 'creates a directory with the default action' do
expect(chef_run).to create_directory('/u01/app/oraInventory')
expect(chef_run).to create_directory('/oradata')
end
end
配方文件:
my_secret_key = Chef::EncryptedDataBagItem.load_secret("/etc/secret_key")
passwords = Chef::EncryptedDataBagItem.load("databags", "databag_passwords", my_secret_key)
您能否建议如何解决此问题。我只在我的厨师工作站上运行测试。