Hi,
I have below manifests
class module_name {
if str2bool("$::is_virtual") == true {
$p1 = 'package-name'
if $::operatingsystemmajrelease < '7' {
package {["${p1}-pae"]: ensure => installed }
}
else {
package {$p1: ensure => installed }
}
}
}
}
rspec-puppet test is,
require 'spec_helper'
describe 'module_name' do
it { should contain_class('module_name') }
osver = '5'
if osver < '7'
p1 = 'package-name'
it { should contain_package("#{p1}-pae").with_ensure('installed')}
end
if osver == '7'
p1 = 'package-name'
it { should contain_package(p1).with_ensure('installed')}
end
end
The above test case worked with out any issues. But if I change the value to osver = '7', getting below error
Failure/Error: it { should contain_package('package-name').with_ensure('installed')}
expected that the catalogue would contain Package[package-name]
I know the cause of the error, because rspec-puppet will only re-compile the catalog there are changes in facts or variable.
But it won't be satisfied because the catalog was already compiled for a previous test, so its not accepting the changed value test case.
so, is there any option to clear the previously compiled test case catalog and re-compile the catalog if we cahnge any "if condition" or facts.
I know about mock function, but it works only for custom function and hiera.
Do we have any other alternate for my test case.
↧