how to pass selector value to hiera in rspec-puppet
Hi,
I have following code in puppet,
class module_name {
$val = hiera('ONOFF')
case $val {
'off' : {
service { 'servicename' :
ensure => stopped,
enable => false,
}
}
'on' : {
service { 'servicename' :
ensure => running,
enable => true,
}
}
default: {}
}
}
Below is the test case
describe 'module_name' do
context 'with defaults valuess' do
let(:facts) {{ :operatingsystemmajrelease => '7', :osfamily => 'RedHat'}}
it { should contain_class('module_name') }
end
context 'test case for off' do
let(:facts) {{ :operatingsystemmajrelease => '7', :osfamily => 'RedHat' }}
let(:hiera_config) { 'spec/fixtures/hiera.yaml' }
hiera = Hiera.new({ :config => 'spec/fixtures/hiera.yaml' })
it { should contain_service('servicename').with(
'ensure' => 'stopped',
'enable' => 'false'
)}
end
context 'test case for on' do
let(:facts) {{ :operatingsystemmajrelease => '7', :osfamily => 'RedHat' }}
let(:hiera_config) { 'spec/fixtures/hiera.yaml' }
hiera = Hiera.new({ :config => 'spec/fixtures/hiera.yaml' })
it { should contain_service('servicename').with(
'ensure' => 'running',
'enable' => 'true'
)}
end
end
===============================================
default.yaml
---
ONOFF: 'on'
Getting below error
expected that the catalogue would contain Service[servicename] with ensure set to "stopped" but it is set to "running", and parameter enable set to "false" but it is set to true
How I can write test case to pass both selector "on" and "off".