Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: rodjek/rspec-puppet
...
head fork: rodjek/rspec-puppet
  • 3 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
Commits on Aug 04, 2011
@rodjek WIP cc385e3
Commits on Aug 05, 2011
@rodjek It works ac4bc43
Commits on Aug 09, 2011
@rodjek Support for mocking exported resources 52e267f
View
4 lib/rspec-puppet/example/class_example_group.rb
@@ -30,8 +30,10 @@ def catalogue
nodename = self.respond_to?(:node) ? node : Puppet[:certname]
facts_val = self.respond_to?(:facts) ? facts : {}
+ virt_res = self.respond_to?(:virtual_resources) ? virtual_resources : []
+ exp_res = self.respond_to?(:exported_resources) ? exported_resources : []
- build_catalog(nodename, facts_val)
+ build_catalog(nodename, facts_val, virt_res, exp_res)
end
end
end
View
4 lib/rspec-puppet/example/define_example_group.rb
@@ -37,8 +37,10 @@ def catalogue
'fqdn' => nodename,
}
facts_val.merge!(facts) if self.respond_to?(:facts)
+ virt_res = self.respond_to?(:virtual_resources) ? virtual_resources : []
+ exp_res = self.respond_to?(:exported_resources) ? exported_resources : []
- build_catalog(nodename, facts_val)
+ build_catalog(nodename, facts_val, virt_res, exp_res)
end
end
end
View
2  lib/rspec-puppet/matchers/create_generic.rb
@@ -23,7 +23,7 @@ def matches?(catalogue)
ret = true
resource = catalogue.resource(@referenced_type, @title)
- if resource.nil?
+ if resource.nil? or resource.virtual?
ret = false
else
if @expected_params
View
65 lib/rspec-puppet/support.rb
@@ -1,10 +1,71 @@
+class Puppet::Parser::Compiler
+ def compile
+ set_node_parameters
+ create_settings_scope
+
+ evaluate_main
+
+ evaluate_ast_node
+
+ mock_resources.each do |r|
+ add_resource(topscope, r)
+ end
+
+ evaluate_node_classes
+
+ evaluate_generators
+
+ finish
+
+ fail_on_unevaluated
+
+ @catalog
+ end
+end
+
+class Puppet::Parser::Collector
+ def collect_exported
+ if @equery =~ /param_values.value = '(.*?)' and param_names.name = '(.*?)'/
+ param_value = $1
+ param_name = $2.to_sym
+ end
+
+ mock_resources.select { |r| r[param_name] == param_value }
+ end
+end
+
module RSpec::Puppet
- module Support
- def build_catalog nodename, facts_val
+ module Support
+ def build_catalog(nodename, facts_val, virt_res, exp_res)
node_obj = Puppet::Node.new(nodename)
node_obj.merge(facts_val)
+ virt_res = [virt_res] if virt_res.is_a? Hash
+ exp_res = [exp_res] if exp_res.is_a? Hash
+
+ scope = Puppet::Parser::Scope.new
+
+ mock_virtual_resources = virt_res.map do |r|
+ res = Puppet::Parser::Resource.new(r[:type], r[:title], {:virtual => true, :scope => scope})
+ r[:parameters].keys.each { |k| res[k] = r[:parameters][k] }
+ res
+ end
+
+ mock_exported_resources = exp_res.map do |r|
+ res = Puppet::Parser::Resource.new(r[:type], r[:title], :virtual => true, :exported => true, :scope => scope)
+ r[:parameters].keys.each { |k| res[k] = r[:parameters][k] }
+ res
+ end
+
+ Puppet::Parser::Compiler.any_instance.stub(:mock_resources).and_return(mock_virtual_resources + mock_exported_resources)
+ Puppet::Parser::Collector.any_instance.stub(:mock_resources).and_return(mock_exported_resources)
+
+ require 'puppet/rails'
+ Puppet::Rails.stub(:init).and_return(true)
+ Puppet.features.stub(:rails?).and_return(true)
+ Puppet.settings.set_value(:storeconfigs, true, :memory, :dont_trigger_handles => true)
+
# trying to be compatible with 2.7 as well as 2.6
if Puppet::Resource::Catalog.respond_to? :find
Puppet::Resource::Catalog.find(node_obj.name, :use_node => node_obj)
View
25 spec/classes/exported_realise_file_spec.rb
@@ -0,0 +1,25 @@
+require 'spec_helper'
+
+describe 'exported::realise_file' do
+ let(:exported_resources) { [
+ {
+ :type => 'file',
+ :title => 'foo',
+ :parameters => {
+ :owner => 'root',
+ :group => 'root',
+ }
+ },
+ {
+ :type => 'file',
+ :title => 'foobar',
+ :parameters => {
+ :owner => 'daemon',
+ :group => 'daemon',
+ }
+ }
+ ] }
+
+ it { should contain_file('foo').with_owner('root').with_group('root') }
+ it { should_not contain_file('foobar') }
+end
View
16 spec/classes/virtual_realise_file_spec.rb
@@ -0,0 +1,16 @@
+require 'spec_helper'
+
+describe 'virtual::realise_file' do
+ let(:virtual_resources) {
+ {
+ :type => 'file',
+ :title => 'foo',
+ :parameters => {
+ :owner => 'root',
+ :group => 'root',
+ }
+ }
+ }
+
+ it { should contain_file('foo').with_owner('root').with_group('root') }
+end
View
3  spec/fixtures/exported/manifests/realise_file.pp
@@ -0,0 +1,3 @@
+class exported::realise_file {
+ File<<| owner == 'root' |>>
+}
View
3  spec/fixtures/virtual/manifests/realise_file.pp
@@ -0,0 +1,3 @@
+class virtual::realise_file {
+ File<| |>
+}

No commit comments for this range

Something went wrong with that request. Please try again.