Discussion:
[Puppet Users] rspec testing; how to test a subclass that requires another class
Trey Ormsbee
2015-05-01 21:47:26 UTC
Permalink
I have a puppet module that I am not sure hot to write a test for: Example
below:

class appsuite (
$param1,
$param2,
$param3,
$param4,
) {

include appsuite::params
include appsuite::repo
include appsuite::preconfig

}

#nothing in params, repo or preconfig really matter, other then preconfig
lays down a shared settings file: /etc/appsuite/settings
# /etc/appsuite/settings is required to be in place during the install of
any component of appsuite as it is sued to do its own setup.

So then I have a seperate class

class appsuite::component1 (
$component_param1,
$component_param2,
) {

...
package { 'component1': ensure => installed }
...
}


Now, class appsuite::component1 requires appsuite to be defined and all
those classes to be ran before it starts all it's magic. How do I test
that?

I got this

describe 'appsuite' do
context "test appsuite" do
let :params do {
param1 = 'blah1',
param2 = 'blah2',
param3 = 'blah3',
param4 = 'blah4',
}
end
it { is_expected.to contain_file('/etc/appsuite/settings').with({'mode'
=> '0644'}) }
end
end

Now the above works fine, but I do not understand how to then call
appsuite::component1 from that test with those parameters, I tried
nesting in the descibe, but it then says i need to pass params to
appsuite. Seems like this would be a pretty common thing to do so I hope I
am just missing something.

Any ideas?


Thanks
Trey
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/9f1a987b-a9d6-4f8a-befa-187c72d6d797%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Gavin Williams
2015-05-02 08:39:38 UTC
Permalink
Trey

You can use "let(:pre_condition)" to include any dependencies when testing...

E.g. https://github.com/fatmcgav/fatmcgav-glassfish/blob/develop/spec/classes/install_spec.rb#L14

Gav
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/14567b74-2489-49d6-bc5c-002550574c90%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Trey Ormsbee
2015-05-03 02:10:30 UTC
Permalink
Thank you, That is exactly what I was looking for. It's hard to actually
google that info :\
Post by Gavin Williams
Trey
You can use "let(:pre_condition)" to include any dependencies when testing...
E.g.
https://github.com/fatmcgav/fatmcgav-glassfish/blob/develop/spec/classes/install_spec.rb#L14
Gav
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/dac145d0-3d53-4eff-8473-9a031c0517ec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...