【发布时间】:2021-08-21 18:29:14
【问题描述】:
我试图达到这样的条件,如果组存在于服务器中,它应该通过,如果不存在,它应该跳过并且不应该显示为失败
describe.one do
describe 'testgroup' do
expect(bash("ipa group-show testgroup").exit_status).to eq 0
it { should exist }
end
describe 'testgroup' do
expect(bash("ipa group-show testgroup").exit_status).to_not eq 0
it { should_not exist }
end
end
执行后使用:
# inspec exec testgroup_test.rb
它抛出错误输出为:
undefined method 'bash' for Rspec::ExampleGroups (No method Error).
请指教,如何在inspec中实现这样的条件测试。
【问题讨论】:
-
如果组不存在也没关系,为什么要测试它呢?如果条件不匹配,不确定是否要编写一个不会失败的测试。
-
该脚本在 2 个不同的环境中是通用的,在一个环境中,如果它可用,则测试应该通过,而在另一个环境中,该组不可用,它应该跳过并且不会显示失败
标签: chef-infra inspec