When I began testing puppet catalogs with cucumber-puppet, I soon stumbled upon the problem of exported resources. As cucumber-puppet does not deal with database connections out of the box, it was at first glance impossible to test, e.g. if your nagios server was configured properly from a service module. This weekend I finally took the time to look at the way puppet uses exported resources and realized an easy way to make them work with cucumber-puppet.
The main trick is to use an sqlite3 in-memory database so that cucumber-puppet won’t have to connect to any external database or mess with the filesystem too much. With the database in place, you can access exported resources through their model class Puppet::Rails::Resource. I used database_cleaner to ensure empty databases between scenarios. The only nuisance so far is, that puppet will want to create several directories with storeconfigs activated, so we have to manage a temporary directory.
Here is a sample usage of exported resources with cucumber-puppet:
I plan to add proper support for exported resources to cucumber-puppet in the future, but this blog post should be enough to get you started.
Was this blog post helpful to you? Do you have any ideas on improving cucumber-puppet? Let me know in the comments!