単体テストを既存のモジュール (自分で作成したものではない) に改造しています。undef
params クラスの値を値にオーバーライドできないようですhash
。
params クラスには次のものがあります (抜粋のみ)。
class myclass::params {
splunk = undef,
...
}
主なクラス (抜粋のみ):
class myclass(
$splunk = $myclass::params::splunk,
...
) inherits ::myclass::params
{...}
そして、次の構成クラス (抜粋のみ):
class mylcass::config inherits myclass{
if $myclass::splunk['install']['package_manage'] {
file { "somefile.conf":
ensure => file,
mode => '0444',
source => 'puppet:///modules/myclass/splunk/somefile.conf',
}
...
}
}
config_spec.rb ファイルには次のものがあります。
require 'spec_helper'
require 'shared_contexts'
describe 'myclass::splunk::config' do
hiera = Hiera.new(:config => 'spec/fixtures/hiera/hiera.yaml')
splunk = hiera.lookup('splunk',nil,nil)
let(:params) do
{
}
end
it do
is_expected.to contain_file('somefile.conf')
.with(
'ensure' => 'file',
'mode' => '0444',
'source' => 'puppet:///modules/myclass/splunk/somefile.conf'
)
end
end
オーバーライドされることを期待して、hiera ルックアップをsplunk
myclass_spec.rb ファイルにプラグインしました。
require 'spec_helper'
require 'shared_contexts'
describe 'myclass' do
hiera = Hiera.new(:config => 'spec/fixtures/hiera/hiera.yaml')
splunk = hiera.lookup('splunk',nil,nil)
let(:params) do
{
:splunk => splunk
...
}
しかし、次のエラーが引き続き発生します。
myclass::splunk is not a hash or array when accessing it
splunk
変数をオーバーライドするにはどうすればよいですか?