Test define in module with rspec_puppet

29 views
Skip to first unread message

Thomas Bendler

unread,
Feb 16, 2016, 4:38:39 AM2/16/16
to puppet-users
Hi @all,

I have a small problem with my module test using spec_puppet. I use the Puppetlabs MySQL module to create databases in my module. When running "rake spec" my coverage report that not all resources are tested:

​<--- snip --->​
Mysql_database[test1]
Mysql_grant[test1@localhost/test1.*]
Mysql_user[test1@localhost]
​<--- snap --->​

​How can I include this resources in my spec file to get tested also? I've already added the classes to the spec file but this did not solve the problem:

<--- snip --->
it { is_expected.to contain_class('mysql::server') }
it { is_expected.to contain_class('mysql::server::backup') }
it { is_expected.to contain_class('mysql::server::account_security') }
it { is_expected.to contain_class('mysql::server::mysqltuner') }
<--- snap --->

Is it necessary to create a spec file for each define? Are there any public examples that I can use for education?

Regards Thomas​
--
Linux ... enjoy the ride!

Gareth Rushgrove

unread,
Feb 16, 2016, 9:29:05 AM2/16/16
to puppet...@googlegroups.com
On 16 February 2016 at 09:37, Thomas Bendler <thomas....@gmail.com> wrote:
> Hi @all,
>
> I have a small problem with my module test using spec_puppet. I use the
> Puppetlabs MySQL module to create databases in my module. When running "rake
> spec" my coverage report that not all resources are tested:
>
> <--- snip --->
> Mysql_database[test1]
> Mysql_grant[test1@localhost/test1.*]
> Mysql_user[test1@localhost]
> <--- snap --->
>
> How can I include this resources in my spec file to get tested also? I've
> already added the classes to the spec file but this did not solve the
> problem:
>
> <--- snip --->
> it { is_expected.to contain_class('mysql::server') }
> it { is_expected.to contain_class('mysql::server::backup') }
> it { is_expected.to contain_class('mysql::server::account_security') }
> it { is_expected.to contain_class('mysql::server::mysqltuner') }
> <--- snap --->
>

You should be able to do something like the following if memory serves:

it { is_expected.to contain_mysql_database('test1') }

Gareth


> Is it necessary to create a spec file for each define? Are there any public
> examples that I can use for education?
>
> Regards Thomas
> --
> Linux ... enjoy the ride!
>
> --
> 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/CAELoU1Pt%3Db1zjGOLrcsp-rEbO%2Bncy_Jv-cu-bqRGXY%3DrsATkHg%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.



--
Gareth Rushgrove
@garethr

devopsweekly.com
morethanseven.net
garethrushgrove.com

Thomas Bendler

unread,
Feb 16, 2016, 9:37:00 AM2/16/16
to puppet-users
Things can be so easy:

Total resources:   56

Touched resources: 56

Resource coverage: 100.00%


Thanks a lot!

Regards Thomas


For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages