I am retrofitting unit tests to an existing module (not authored by myself). I can't seem to override the params class undef
value to a hash
value.
the params class has the following (excerpt only):
class myclass::params {
splunk = undef,
...
}
Main class (excerpt only):
class myclass(
$splunk = $myclass::params::splunk,
...
) inherits ::myclass::params
{...}
And the following config class (excerpt only):
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',
}
...
}
}
In config_spec.rb file I have the following:
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
I plugged the hiera lookup for splunk
into the myclass_spec.rb file in the hope it will override:
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
...
}
But I continue to get the following error:
myclass::splunk is not a hash or array when accessing it
How do I override the splunk
variable?