我创建了一个简单的 Puppet 4 类和一个单元测试,如下所示(在执行touch metadata.json; rspec-puppet-init
while in之后modules/test/
):
# modules/test/manifests/hello_world1.pp
class test::hello_world1 {
file { "/tmp/hello_world1":
content => "Hello, world!\n"
}
}
# modules/test/spec/classes/test__hello_world1_spec.rb
require 'spec_helper'
describe 'test::hello_world1' do
it { is_expected.to compile }
it { is_expected.to contain_file('/tmp/hello_world1')\
.with_content(/^Hello, world!$/) }
end
我可以通过执行rspec spec/classes/test__hello_world1_spec.rb
while in来成功运行单元测试modules/test/
。
我现在想继续学习一个更高级的类,它使用来自另一个模块的代码,即concat
(该模块已经安装在 arleady 中modules/concat
):
# modules/test/manifests/hello_world2.pp
class test::hello_world2
{
concat{ "/tmp/hello_world2":
ensure => present,
}
concat::fragment{ "/tmp/hello_world2_01":
target => "/tmp/hello_world2",
content => "Hello, world!\n",
order => '01',
}
}
# modules/test/spec/classes/test__hello_world2_spec.rb
require 'spec_helper'
describe 'test::hello_world2' do
it { is_expected.to compile }
# ...
end
当我尝试使用rspec spec/classes/test__hello_world2_spec.rb
while in运行此单元测试时,modules/test
我收到一条错误消息,其中包括:
失败/错误:编译期间它 { is_expected.to compile } 错误:评估错误:评估资源语句时出错,未知资源类型:'concat'
我怀疑根本原因是rspec
找不到其他模块,因为它没有被告知“模块路径”。
我的问题是:我应该如何开始单元测试,尤其是需要访问其他模块的单元测试?