Chef infra Serverspec包检查始终返回true
我正在尝试编写serverspec测试,通过使用chef、kitchen和vagrant以及debian jessie box来检查食谱是否正在设置mariadb服务器 配方很简单:Chef infra Serverspec包检查始终返回true,chef-infra,chef-recipe,test-kitchen,serverspec,Chef Infra,Chef Recipe,Test Kitchen,Serverspec,我正在尝试编写serverspec测试,通过使用chef、kitchen和vagrant以及debian jessie box来检查食谱是否正在设置mariadb服务器 配方很简单: # cookbooks/mariadb/recipes/server.rb package 'mariadb-server' do action :install end 我为它编写的规范是: # cookbooks/mariadb/test/integration/default/serverspec/se
# cookbooks/mariadb/recipes/server.rb
package 'mariadb-server' do
action :install
end
我为它编写的规范是:
# cookbooks/mariadb/test/integration/default/serverspec/server_spec.rb
require 'spec_helper'
describe 'mariadb::server' do
context package('mariadb-server') do
it 'is installed' do
expect be_installed
end
end
end
但是,当运行kitchen verify
时,无论包的状态如何,都会返回true。如果我ssh到vagrant框中并移除包,然后运行kitchen verify
,我也会得到一个肯定的结果
即使我将包更改为某个随机字符串,例如上下文包(“this-is-not-a-package”),也要执行测试结果为真
我在这里做错了什么?从更一般的意义上讲,这并没有遵循RSpec 3 matcher语法
你可以考虑这样做:
describe 'mariadb::server' do
describe package('mariadb-server') do
it { expect(subject).to be_installed }
end
end
这看起来更干净,输出也更干净,因为serverspec将文档格式化程序用于RSpec输出
为了进一步让您了解引擎盖下发生的事情,以便您了解这里发生的事情,而不是假设这一切都是魔术,以下是如何进行此类检查的通用模板:
describe method(argument) do
it { expect(subject).to be_boolean-matcher.with_chain(argument_two) }
end
对于您的情况(您没有使用版本
链,但我添加了它以获取额外信息)
- 方法:包装
- 参数:mariadb服务器
- 主题:将解析为包(mariadb服务器)
- 布尔匹配器:已安装
- 链:版本
- 论点二:1.2.3