Puppet-Rspec - Can it test for smart paramaters

23 views
Skip to first unread message

James Perry

unread,
Feb 7, 2017, 3:58:05 PM2/7/17
to Puppet Developers
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. 

  Thanks! 

Martin Alfke

unread,
Feb 8, 2017, 7:58:57 AM2/8/17
to puppe...@googlegroups.com
Hi James,
> On 07.02.2017, at 21:58, James Perry <jjpe...@gmail.com> 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

Reply all
Reply to author
Forward
0 new messages