我正在使用InSpec创建我的测试。这是我对Apache的测试:
require 'inspec'
if os[:family] == 'redhat'
describe package 'httpd' do
it { should be_installed }
end
describe service 'httpd' do
it { should be_enabled }
it { should be_running }
end
describe file '/etc/httpd/conf/httpd.conf' do
it { should be_file }
end
end
describe port(80) do
it { should_not be_listening }
end
describe port(9000) do
it { should be_listening }
end我的问题与上下文相关。在使用InSpec之前,我使用了ChefSpec,我喜欢它创建上下文和输出显示上下文的方式。对于上面的示例,输出如下:
System Package
✔ httpd should be installed
Service httpd
✔ should be enabled
✔ should be running
File /etc/httpd/conf/httpd.conf
✔ should be file
Port 80
✔ should not be listening
Port 9000
✔ should be listening我希望在输出中包含家庭风格或版本或arch,以便了解并获得更清晰的测试输出。
有什么建议吗?
发布于 2016-12-06 00:01:04
首先,ChefSpec和InSpec做的是完全不同的事情,所以两者是可以比较的。其次,虽然InSpec支持一定程度的RSpec语法兼容性,但它远不如ChefSpec或ServerSpec那么完整,这两个库都是完整的RSpec帮助器库。正如@Tensibai提到的,InSpec提供了自己的custom syntax for more complex tests。如果您特别想使用RSpec describe和context block系统或自定义RSpec格式化程序,我建议您改用ServerSpec。
发布于 2019-01-29 01:27:26
我认为您正在寻找一种更好地控制输出的方法。如果是这样,Chef建议您使用expect语法。尽管他们说它的可读性不如should语法,但它是定制输出的唯一方法。
例如,如果运行此控件:
control 'Services' do
title 'Check that the required services are installed and running.'
if os['family'] == 'darwin'
describe 'For Mac OS, the Apache service' do
it 'should be installed and running.' do
expect(service('httpd')).to(be_installed)
expect(service('httpd')).to(be_running)
end
end
describe 'For Mac OS, the Docker service' do
it 'should be installed and running.' do
expect(service('docker')).to(be_installed)
expect(service('docker')).to(be_running)
end
end
end
end您将获得以下输出:
× Services: Check that the required services are installed and running. (1 failed)
× For Mac OS, the Apache service should be installed and running.
expected that `Service httpd` is installed
✔ For Mac OS, the Docker service should be installed and running.https://stackoverflow.com/questions/40976305
复制相似问题