Jennings, Jared L CTR USAF AFMC 96 SK/CCI
2013-Apr-16 19:42 UTC
[Puppet Users] testing custom types?
I''m having scads of fun with custom resource types. But mine are getting complicated enough that not having automated tests for them is starting to seem really foolish. But the latest things I''ve seen about that issue are from three years ago (<https://github.com/mikepea/puppet-git>, <http://projects.puppetlabs.com/issues/3138>). There''s a lot written about puppet-rspec, but that''s for testing your manifests, not for testing your custom types. What am I missing? -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
On 16/04/13 20:42, Jennings, Jared L CTR USAF AFMC 96 SK/CCI wrote:> I''m having scads of fun with custom resource types. But mine are getting > complicated enough that not having automated tests for them is starting > to seem really foolish. But the latest things I''ve seen about that issue > are from three years ago (<https://github.com/mikepea/puppet-git>, > <http://projects.puppetlabs.com/issues/3138>). There''s a lot written > about puppet-rspec, but that''s for testing your manifests, not for > testing your custom types. What am I missing?You can do it just with plain rspec and puppetlabs_spec_helper (which initialises Puppet for you). There some instructions on setting up the spec_helper and Rakefile here: https://github.com/puppetlabs/puppetlabs_spec_helper I have a basic spec_helper based on the pl_spec_helper example: https://github.com/hercules-team/augeasproviders/blob/master/spec/spec_helper.rb The only gotcha I''ve found are a couple of versions of Puppet (2.7.20+ and 3.0.x) which don''t load custom types from lib/ in the module, so there''s a workaround in the above file. Here''s an example of a simple spec that tests a parameter munge block in a type: https://github.com/hercules-team/augeasproviders/blob/master/spec/unit/puppet/shellvar_type_spec.rb https://github.com/hercules-team/augeasproviders/blob/master/lib/puppet/type/shellvar.rb (the type itself) You''ll find other files in the same directory which test the providers, though since it''s fairly specialised they''re not great examples. I''d recommend working from the huge number of examples in the Puppet source tree itself: https://github.com/puppetlabs/puppet/tree/master/spec/unit/type https://github.com/puppetlabs/puppet/tree/master/spec/unit/provider Hope that helps. -- Dominic Cleal Red Hat Engineering -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
Jennings, Jared L CTR USAF AFMC 96 SK/CCI
2013-Apr-17 19:07 UTC
RE: [Puppet Users] testing custom types?
> The only gotcha I''ve found are a couple of versions of Puppet (2.7.20+ > and 3.0.x) which don''t load custom types from lib/ in the module, so > there''s a workaround in the above file.This seemingly innocuous statement has cleared up for me the problem of being unable to require, from my custom types and providers, sundry Ruby modules I wrote. I thought Puppet wouldn''t let me use my own Ruby modules at all, and now to my great relief I see I was quite wrong. The other things you''ve said about the spec helper are also very helpful and complete. Thanks very much! -- 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+unsubscribe@googlegroups.com. To post to this group, send email to puppet-users@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-users?hl=en. For more options, visit https://groups.google.com/groups/opt_out.