我有一个测试:
control "cis-0-0-7" do
impact 1.0
title "verify chkconfig"
desc "verify chkconfig"
stdout, stderr, status = Open3.capture3('chkconfig | grep active')
puts stdout
#stdout { should match /activemq-instance-EL2-ext/ }
#end
end
这将在标准输出上显示以下内容:
$inspec exec cookbooks/activemq7/test/linuxcommon_test.rb
activemq-instance-EL2-ext 0:off 1:off 2:on 3:on 4:on 5:on 6:off
activemq-instance-EL2-int 0:off 1:off 2:on 3:on 4:on 5:on 6:off
我如何使用 Inspec(如果可能)或使用 ruby 来解析和验证(断言)这些多行。
正如@coderanger 建议的那样,我使用了:
control "cis-0-0-7" do
impact 1.0
title "verify chkconfig"
desc "verify chkconfig"
#stdout, stderr, status = Open3.capture3('chkconfig | grep active')
output = command('chkconfig | grep active')
describe output do
its('stdout') { should match /activemq-instance-EL2-ext.*\n/ }
its('stdout') { should match /activemq-instance-EL2-int.*\n/ }
end
end
作品!!谢谢