Hi James,
> On 07.02.2017, at 21:58, James Perry <[email protected]> wrote:
>
> I have started to use Smart Parameters in Puppet, as I am running Foreman
> with Puppet, and I started writing a new module where I am going to be
> setting smart parameters.
>
> Is there a way with the puppet-rspec tests to check that the smart parameter
> was set? If they can be tested to be set I would like to include that as
> part of the module and associated functions.
you can test whether your Puppet module will add relevant resources to the
catalog.
It seems as if you now have a parameterized class and you want to test that
everything is working when passing values to them.
You can easily do this with the let(:params) syntax in rspec-puppet.
e.g. lets assume the following puppet code:
class my_app (
$dev_env = false,
){
if $dev_env {
file { ‘/etc/my_app/debug.conf’:
ensure => file,
}
} else {
file { ‘/etc/my_app/debug.conf’:
ensure => absent,
}
}
}
Your rspec test can set the value. See following example:
describe ‘my_app’ do
context ‘with default value’ do
it { is_expected.to
contain_file(‘/etc/my_app/debug.conf’).with_ensure(‘absent’) }
end
context ‘on dev platform’ do
let(:params) {{ :dev_env = true }}
it { is_expected.to
contain_file(‘/etc/my_app/debug.conf’).with_ensure(‘file’) }
end
end
hth,
Martin
--
You received this message because you are subscribed to the Google Groups
"Puppet Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-dev/930E3FA3-57B4-43AC-9C44-F3DBAB5A56EC%40gmail.com.
For more options, visit https://groups.google.com/d/optout.