由于实现了this的答案,我能够使用rspec-puppet
测试自定义类型
问题。
但是,我想避免通过模拟
cystom类型
在每个puppet模块中创建指向自定义文件夹
的符号链接(symbolic link)。
问题是如何在 Rspec-Puppet 中模拟自定义 Puppet 类型。
我找到了一个example关于自定义 Puppet Function
的模拟,但我正在寻找一个模拟 Puppet Custom Types
的示例。
puppet 代码
class vim::ubuntu::config {
custom_multiple_files { 'line_numbers':
ensure => 'present',
parent_dir => '/home',
file_name => '.vimrc',
line => 'set number';
}
}
Rspec-puppet 代码
require 'spec_helper'
describe "vim::ubuntu::config" do
?
end
最佳答案
寻找模拟示例的一个好地方是 Puppet 自己的集合 unit tests .
我不确定是否有需要考虑的特殊性,但在 Puppet 的规范测试中,模拟的工作原理如下:
let(:type) { Puppet::Type.type(:custom_file_line) }
it "should do whatever"
type.stubs(:retrieve).returns <value>
# perhaps also needed
Puppet::Type.stubs(:type).with(:custom_file_line).returns(type)
据我了解,这是moccha风格 mock 。在普通的 rspec 中,模拟/ stub 有点多 involved ,这对于 rspec-puppet 可能是必需的。
关于mocking - 如何在 Rspec-Puppet 中模拟自定义类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23060142/