我正在尝试开始使用 rspec 来测试一些已经制作(和生产中)的 puppet 模块,但是这件事一直想让我生气。
首先,我正在使用 rake 进行“完整”测试。任务是:
耙文件:
desc 'Validate manifests, templates, and ruby files'
task :validate do
Dir['manifests/**/*.pp'].each do |manifest|
sh "puppet parser validate --noop #{manifest}"
end
Dir['spec/**/*.rb', 'lib/**/*.rb'].each do |ruby_file|
sh "ruby -c #{ruby_file}" unless ruby_file =~ %r{spec/fixtures}
end
Dir['templates/**/*.erb'].each do |template|
sh "erb -P -x -T '-' #{template} | ruby -c"
end
end
desc 'Run metadata_lint, lint, validate, and spec tests.'
task :test do
[:metadata_lint, :lint, :validate, :spec].each do |test|
Rake::Task[test].invoke
end
我遇到的第一个问题是这个错误:
1) rcphp should contain Package[rcphp]
Failure/Error: it { is_expected.to contain_package('rcphp') }
Puppet::PreformattedError:
Evaluation Error: Error while evaluating a Resource Statement, Could not find declared class rcphp at line 1:1 on node test.example.com
经过一段时间的研究,我发现我应该把我正在使用的模块放在 .fixtures.yml 中。听起来很简单,所以我做了:
fixtures:
symlinks:
rcphp: "#{source_dir}"
repositories:
php: "git://github.com/voxpupuli/puppet-php.git"
inifile: "git://github.com/puppetlabs/puppetlabs-inifile.git"
forge_modules:
stdlib:
repo: "puppetlabs/stdlib"
ref: "4.12.0"
从现在开始,事情就没有任何意义了。我得到了错误:
Failure/Error: contain "::yum::repo::${yum_repo}"
Puppet::PreformattedError:
Evaluation Error: Error while evaluating a Function Call, Could not find class ::yum::repo::remi_php56 for test.example.com at /home/luis.brandao/git/rcphp/spec/fixtures/modules/php/manifests/repo/redhat.pp:12:3 on node test.example.com
::yum::repo 由 PHP 模块调用。php 模块有自己的固定装置。我尝试添加它,然后弹出另一个嵌套模块依赖项。这不可能,我应该弄清楚并手动添加所有依赖关系树以进行简单测试?