rspec-puppet with module dependencies

689 views
Skip to first unread message

John Julien

unread,
Feb 21, 2014, 11:02:27 PM2/21/14
to puppe...@googlegroups.com
Hi,
I am attempting to write spec tests for a trac module I'm working on that has several dependencies, one of which is puppetlabs-postgresql.  I am running into an issue with my spec tests as the puppet code fails to compile because it can't' find the classes/defined types/functions from my calls out to other modules.

So, for example, this particular bit of code throws the error: Could not find class postgresql::server

define trac::db($db_user,
                $db_pass,
                $db_name) { 

  include 'postgresql::server'
  
  postgresql::server::db {$db_name: 
     user     => $db_user,
     password => postgresql_password($db_user, $db_pass),
  }
  if ( ! defined(Postgresql::Server::Role[$db_user])) {
    postgresql::server::role {$db_user:
      password_hash => postgresql_password($db_user, $db_pass)
    }
  }
}

I also have dependencies on apache.  So, in the define I do want to test, trac::project, I find myself doing things like this:

  let(:pre_condition) {
    "class apache {}
     define apache::mod() {}
     define trac::db() {}
    "
  }

Is there a more sane way of doing this?  Is my thinking completely off? Any help is appreciated.

Thanks,
John

johan-OF

unread,
Feb 22, 2014, 5:04:51 AM2/22/14
to puppe...@googlegroups.com
Have a look at rpec-pupept and the .fixture.yaml file.

http://puppetlabs.com/blog/the-next-generation-of-puppet-module-testing

an expert from the text :

.fixtures.yml. This file is used by the common rake tasks to automatically install dependencies for test runs. For our example, its contents should be:
fixtures:
  repositories:
    stdlib: git://github.com/puppetlabs/puppetlabs-stdlib.git
  symlinks:
    apache: "#{source_dir}"

This defines a testing environment with two modules: one called ‘stdlib’ fetched from a Github repository, and one called ‘apache’ (our module) which will be a symlink to the current source directory.

Grts

Jo

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-dev/f05a050a-a614-4d15-bf9c-1f3ae541770c%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Upcoming Events:

Zabbix Certified Training | http://www.open-future.be/zabbix-certified-training-10-till-12th-march

Zabbix for Large Environments Training | http://www.open-future.be/zabbix-large-environments-training-13-till-14th-march

Puppet Introduction Course | http://www.open-future.be/puppet-introduction-course-14th-april

Puppet Advanced Training | http://www.open-future.be/puppet-advanced-training-15-till-17th-april

Subscribe to our newsletter: http://eepurl.com/BUG8H


John Julien

unread,
Feb 24, 2014, 12:19:41 PM2/24/14
to puppe...@googlegroups.com


On Saturday, February 22, 2014 4:04:51 AM UTC-6, Johan De Wit wrote:
Have a look at rpec-pupept and the .fixture.yaml file.

http://puppetlabs.com/blog/the-next-generation-of-puppet-module-testing

an expert from the text :

.fixtures.yml. This file is used by the common rake tasks to automatically install dependencies for test runs. For our example, its contents should be:
fixtures:
  repositories:
    stdlib: git://github.com/puppetlabs/puppetlabs-stdlib.git
  symlinks:
    apache: "#{source_dir}"

This defines a testing environment with two modules: one called ‘stdlib’ fetched from a Github repository, and one called ‘apache’ (our module) which will be a symlink to the current source directory.

Grts

Jo

Thanks Johan,
I was looking http://rspec-puppet.com/  which I didn't see a mention of fixtures.yml.  The puppetlabs_spec_helper has helped get the dependencies for my tests. It looks like it can do some other useful things for me as well.

Thanks!


Reply all
Reply to author
Forward
0 new messages