Skip to content

Instantly share code, notes, and snippets.

@nistude
Created September 4, 2011 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nistude/1192764 to your computer and use it in GitHub Desktop.
Save nistude/1192764 to your computer and use it in GitHub Desktop.
Storeconfigs setup for cucumber-puppet
Feature: storeconfigs
Scenario: export resource
Given a node of class "exporting"
When I compile its catalog
Then it should export a resource "File[foo]"
Scenario: collect resource
Given a node of class "collecting"
And an exported resource "File[bar]"
When I compile its catalog
Then there should be a resource "File[bar]"
class exporting {
@@file { "foo": }
}
class collecting {
File <<||>>
}
Given /^an exported resource "([^"]*)"$/ do |res|
fail("#{res} does not denote a resource") unless res =~ /^([A-Z][a-z]+)\[(.*)\]$/
restype = $1
title = $2
Puppet::Rails::Resource.create!(
:exported => true,
# needs to differ between exporting and collecting host, afaik
# current host should get host_id 1
:host_id => 2,
:restype => restype,
:title => title
)
end
Then /^it should export a resource "([^"]*)"$/ do |res|
found = false
Puppet::Rails::Resource.all.each do |r|
if r.name == res
found = true
break
end
end
fail "#{res} not found in exported resources" unless found
end
require 'active_record'
require 'database_cleaner'
require 'tmpdir'
DatabaseCleaner.strategy = :truncation
# puppet will want to create some directories with storeconfigs
@@vardir = Dir.mktmpdir
Before do
@puppetcfg['confdir'] = File.join(File.dirname(__FILE__), '..', '..')
@puppetcfg['manifest'] = File.join(@puppetcfg['confdir'], 'site.pp')
# for storeconfigs
@puppetcfg['vardir'] = @@vardir
@puppetcfg['storeconfigs'] = true
@puppetcfg['thin_storeconfigs'] = true
@puppetcfg['dblocation'] = ':memory:'
end
After do
# cleanup database after each scenario
DatabaseCleaner.clean
end
at_exit do
# cleanup temporary vardir after cucumber-puppet run
FileUtils.remove_entry_secure @@vardir
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment