Skip to content

Instantly share code, notes, and snippets.

@raphink
Last active December 15, 2015 16:39
Show Gist options
  • Select an option

  • Save raphink/5290802 to your computer and use it in GitHub Desktop.

Select an option

Save raphink/5290802 to your computer and use it in GitHub Desktop.
require 'catalog'
describe 'package' do
subject { Catalog.instance }
# subject { YAML.load_file('/tmp/catalog') }
it { should contain_package('augeas') }
it { should contain_package('augeas-lenses') }
it { should contain_package('augeas-tools') }
end
require 'puppet/node'
require 'puppet/resource/catalog'
require 'puppet/indirector/catalog/rest'
require 'rubygems'
require 'rspec'
require 'rspec-puppet/matchers'
require 'stringio'
require 'catalog'
class Puppet::Resource::Catalog::RestSpec < Puppet::Resource::Catalog::Rest
def compiler
@compiler ||= indirection.terminus(:rest)
#@compiler ||= indirection.terminus(:yaml)
end
def find(request)
return nil unless catalog = compiler.find(request)
RSpec::configure do |c|
c.include(RSpec::Puppet::ManifestMatchers)
end
# TODO: try to pass the catalog to the examples
Catalog.setup('foo')
# Test by classes, including $certname
spec_dirs = []
catalog.classes.each do |c|
class_dir = c.gsub(/:/, '_')
class_path = "#{Puppet.settings[:libdir]}/spec/class/#{class_dir}"
spec_dirs << class_path if File.directory? class_path
end
out = StringIO.new
unless RSpec::Core::Runner::run(spec_dirs, $stderr, out) == 0
raise Puppet::Error, "Unit tests failed:\n#{out.string}"
end
catalog
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment