Ask Your Question
0

How to write rspec-test for a class that uses 'create_resources' function

asked 2013-08-19 04:57:55 -0500

Can't figure out how to write a puppet-Rspec test for the class, that takes parameters and calls 'create_resources' for defined type, passing resources to that function.

Update: Looks like that I need to test only a httpd::vhost_template, but don't know how.

Here is the class I stuck with:

class httpd::vhosts($vhosts_config) {

  if $vhosts_config[use_templates] {
    notice 'use templates!'

    create_resources(httpd::vhost_template, $vhosts_config[vhosts])
  }
}

Here is the httpd::vhost_template resource definition

define httpd::vhost_template ($vhost_name, $vhost_url, $vhost_order) {

  $basepath = '/vagrant/httpd2_test'

  validate_string($vhost_name)
  validate_string($vhost_url)
  validate_string($vhost_order)

  $file_name = "${vhost_order}_${vhost_name}.conf"

  file { "${basepath}/conf.d/${file_name}":
    ensure  => file ...
(more)
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
2

answered 2013-08-20 10:23:25 -0500

I found out that 'define' can be tested by it's own (didn't knew that it is possible, when I was asking the question). There's a good example in the beginning of Rspec-puppet tutorial.

edit flag offensive delete link more
0

answered 2017-01-13 06:50:44 -0500

karthikeayan gravatar image

It has to be tested against each of the value in the $vhosts_config[vhosts]

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2013-08-19 04:57:55 -0500

Seen: 2,468 times

Last updated: Jan 13