summaryrefslogtreecommitdiffstats
path: root/spec/unit/indirector/catalog
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/indirector/catalog')
-rwxr-xr-xspec/unit/indirector/catalog/active_record_spec.rb190
-rwxr-xr-xspec/unit/indirector/catalog/compiler_spec.rb444
-rwxr-xr-xspec/unit/indirector/catalog/queue_spec.rb20
-rwxr-xr-xspec/unit/indirector/catalog/rest_spec.rb6
-rwxr-xr-xspec/unit/indirector/catalog/yaml_spec.rb26
5 files changed, 343 insertions, 343 deletions
diff --git a/spec/unit/indirector/catalog/active_record_spec.rb b/spec/unit/indirector/catalog/active_record_spec.rb
index 8678dd6b3..4e9d049a1 100755
--- a/spec/unit/indirector/catalog/active_record_spec.rb
+++ b/spec/unit/indirector/catalog/active_record_spec.rb
@@ -4,138 +4,138 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
describe "Puppet::Resource::Catalog::ActiveRecord" do
- confine "Missing Rails" => Puppet.features.rails?
+ confine "Missing Rails" => Puppet.features.rails?
+ before do
+ require 'puppet/indirector/catalog/active_record'
+ Puppet.features.stubs(:rails?).returns true
+ Puppet::Rails.stubs(:init)
+ @terminus = Puppet::Resource::Catalog::ActiveRecord.new
+ end
+
+ it "should be a subclass of the ActiveRecord terminus class" do
+ Puppet::Resource::Catalog::ActiveRecord.ancestors.should be_include(Puppet::Indirector::ActiveRecord)
+ end
+
+ it "should use Puppet::Rails::Host as its ActiveRecord model" do
+ Puppet::Resource::Catalog::ActiveRecord.ar_model.should equal(Puppet::Rails::Host)
+ end
+
+ describe "when finding an instance" do
before do
- require 'puppet/indirector/catalog/active_record'
- Puppet.features.stubs(:rails?).returns true
- Puppet::Rails.stubs(:init)
- @terminus = Puppet::Resource::Catalog::ActiveRecord.new
+ @request = stub 'request', :key => "foo", :options => {:cache_integration_hack => true}
end
- it "should be a subclass of the ActiveRecord terminus class" do
- Puppet::Resource::Catalog::ActiveRecord.ancestors.should be_include(Puppet::Indirector::ActiveRecord)
+ # This hack is here because we don't want to look in the db unless we actually want
+ # to look in the db, but our indirection architecture in 0.24.x isn't flexible
+ # enough to tune that via configuration.
+ it "should return nil unless ':cache_integration_hack' is set to true" do
+ @request.options[:cache_integration_hack] = false
+ Puppet::Rails::Host.expects(:find_by_name).never
+ @terminus.find(@request).should be_nil
end
- it "should use Puppet::Rails::Host as its ActiveRecord model" do
- Puppet::Resource::Catalog::ActiveRecord.ar_model.should equal(Puppet::Rails::Host)
+ it "should use the Hosts ActiveRecord class to find the host" do
+ Puppet::Rails::Host.expects(:find_by_name).with { |key, args| key == "foo" }
+ @terminus.find(@request)
end
- describe "when finding an instance" do
- before do
- @request = stub 'request', :key => "foo", :options => {:cache_integration_hack => true}
- end
-
- # This hack is here because we don't want to look in the db unless we actually want
- # to look in the db, but our indirection architecture in 0.24.x isn't flexible
- # enough to tune that via configuration.
- it "should return nil unless ':cache_integration_hack' is set to true" do
- @request.options[:cache_integration_hack] = false
- Puppet::Rails::Host.expects(:find_by_name).never
- @terminus.find(@request).should be_nil
- end
+ it "should return nil if no host instance can be found" do
+ Puppet::Rails::Host.expects(:find_by_name).returns nil
- it "should use the Hosts ActiveRecord class to find the host" do
- Puppet::Rails::Host.expects(:find_by_name).with { |key, args| key == "foo" }
- @terminus.find(@request)
- end
-
- it "should return nil if no host instance can be found" do
- Puppet::Rails::Host.expects(:find_by_name).returns nil
-
- @terminus.find(@request).should be_nil
- end
+ @terminus.find(@request).should be_nil
+ end
- it "should return a catalog with the same name as the host if the host can be found" do
- host = stub 'host', :name => "foo", :resources => []
- Puppet::Rails::Host.expects(:find_by_name).returns host
+ it "should return a catalog with the same name as the host if the host can be found" do
+ host = stub 'host', :name => "foo", :resources => []
+ Puppet::Rails::Host.expects(:find_by_name).returns host
- result = @terminus.find(@request)
- result.should be_instance_of(Puppet::Resource::Catalog)
- result.name.should == "foo"
- end
+ result = @terminus.find(@request)
+ result.should be_instance_of(Puppet::Resource::Catalog)
+ result.name.should == "foo"
+ end
- it "should set each of the host's resources as a transportable resource within the catalog" do
- host = stub 'host', :name => "foo"
- Puppet::Rails::Host.expects(:find_by_name).returns host
+ it "should set each of the host's resources as a transportable resource within the catalog" do
+ host = stub 'host', :name => "foo"
+ Puppet::Rails::Host.expects(:find_by_name).returns host
- res1 = mock 'res1', :to_transportable => "trans_res1"
- res2 = mock 'res2', :to_transportable => "trans_res2"
+ res1 = mock 'res1', :to_transportable => "trans_res1"
+ res2 = mock 'res2', :to_transportable => "trans_res2"
- host.expects(:resources).returns [res1, res2]
+ host.expects(:resources).returns [res1, res2]
- catalog = stub 'catalog'
- Puppet::Resource::Catalog.expects(:new).returns catalog
+ catalog = stub 'catalog'
+ Puppet::Resource::Catalog.expects(:new).returns catalog
- catalog.expects(:add_resource).with "trans_res1"
- catalog.expects(:add_resource).with "trans_res2"
+ catalog.expects(:add_resource).with "trans_res1"
+ catalog.expects(:add_resource).with "trans_res2"
- @terminus.find(@request)
- end
+ @terminus.find(@request)
end
+ end
- describe "when saving an instance" do
- before do
- @host = stub 'host', :name => "foo", :save => nil, :merge_resources => nil, :last_compile= => nil, :ip= => nil, :environment= => nil
- @host.stubs(:railsmark).yields
+ describe "when saving an instance" do
+ before do
+ @host = stub 'host', :name => "foo", :save => nil, :merge_resources => nil, :last_compile= => nil, :ip= => nil, :environment= => nil
+ @host.stubs(:railsmark).yields
- @node = stub_everything 'node', :parameters => {}
- Puppet::Node.stubs(:find).returns(@node)
+ @node = stub_everything 'node', :parameters => {}
+ Puppet::Node.stubs(:find).returns(@node)
- Puppet::Rails::Host.stubs(:find_by_name).returns @host
- @catalog = Puppet::Resource::Catalog.new("foo")
- @request = stub 'request', :key => "foo", :instance => @catalog
- end
+ Puppet::Rails::Host.stubs(:find_by_name).returns @host
+ @catalog = Puppet::Resource::Catalog.new("foo")
+ @request = stub 'request', :key => "foo", :instance => @catalog
+ end
- it "should find the Rails host with the same name" do
- Puppet::Rails::Host.expects(:find_by_name).with("foo").returns @host
+ it "should find the Rails host with the same name" do
+ Puppet::Rails::Host.expects(:find_by_name).with("foo").returns @host
- @terminus.save(@request)
- end
+ @terminus.save(@request)
+ end
- it "should create a new Rails host if none can be found" do
- Puppet::Rails::Host.expects(:find_by_name).with("foo").returns nil
+ it "should create a new Rails host if none can be found" do
+ Puppet::Rails::Host.expects(:find_by_name).with("foo").returns nil
- Puppet::Rails::Host.expects(:create).with(:name => "foo").returns @host
+ Puppet::Rails::Host.expects(:create).with(:name => "foo").returns @host
- @terminus.save(@request)
- end
+ @terminus.save(@request)
+ end
- it "should set the catalog vertices as resources on the Rails host instance" do
- @catalog.expects(:vertices).returns "foo"
- @host.expects(:merge_resources).with("foo")
+ it "should set the catalog vertices as resources on the Rails host instance" do
+ @catalog.expects(:vertices).returns "foo"
+ @host.expects(:merge_resources).with("foo")
- @terminus.save(@request)
- end
+ @terminus.save(@request)
+ end
- it "should set host ip if we could find a matching node" do
- @node.stubs(:parameters).returns({"ipaddress" => "192.168.0.1"})
+ it "should set host ip if we could find a matching node" do
+ @node.stubs(:parameters).returns({"ipaddress" => "192.168.0.1"})
- @host.expects(:ip=).with '192.168.0.1'
+ @host.expects(:ip=).with '192.168.0.1'
- @terminus.save(@request)
- end
+ @terminus.save(@request)
+ end
- it "should set host environment if we could find a matching node" do
- @node.stubs(:environment).returns("myenv")
+ it "should set host environment if we could find a matching node" do
+ @node.stubs(:environment).returns("myenv")
- @host.expects(:environment=).with 'myenv'
+ @host.expects(:environment=).with 'myenv'
- @terminus.save(@request)
- end
+ @terminus.save(@request)
+ end
- it "should set the last compile time on the host" do
- now = Time.now
- Time.expects(:now).returns now
- @host.expects(:last_compile=).with now
+ it "should set the last compile time on the host" do
+ now = Time.now
+ Time.expects(:now).returns now
+ @host.expects(:last_compile=).with now
- @terminus.save(@request)
- end
+ @terminus.save(@request)
+ end
- it "should save the Rails host instance" do
- @host.expects(:save)
+ it "should save the Rails host instance" do
+ @host.expects(:save)
- @terminus.save(@request)
- end
+ @terminus.save(@request)
end
+ end
end
diff --git a/spec/unit/indirector/catalog/compiler_spec.rb b/spec/unit/indirector/catalog/compiler_spec.rb
index 8339d1861..755509f53 100755
--- a/spec/unit/indirector/catalog/compiler_spec.rb
+++ b/spec/unit/indirector/catalog/compiler_spec.rb
@@ -8,258 +8,258 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
require 'puppet/indirector/catalog/compiler'
describe Puppet::Resource::Catalog::Compiler do
+ before do
+ Puppet::Rails.stubs(:init)
+ Facter.stubs(:to_hash).returns({})
+ Facter.stubs(:value).returns(Facter::Util::Fact.new("something"))
+ end
+
+ describe "when initializing" do
before do
- Puppet::Rails.stubs(:init)
- Facter.stubs(:to_hash).returns({})
- Facter.stubs(:value).returns(Facter::Util::Fact.new("something"))
+ Puppet.expects(:version).returns(1)
+ Facter.expects(:value).with('fqdn').returns("my.server.com")
+ Facter.expects(:value).with('ipaddress').returns("my.ip.address")
+ end
+
+ it "should gather data about itself" do
+ Puppet::Resource::Catalog::Compiler.new
+ end
+
+ it "should cache the server metadata and reuse it" do
+ compiler = Puppet::Resource::Catalog::Compiler.new
+ node1 = stub 'node1', :merge => nil
+ node2 = stub 'node2', :merge => nil
+ compiler.stubs(:compile)
+ Puppet::Node.stubs(:find).with('node1').returns(node1)
+ Puppet::Node.stubs(:find).with('node2').returns(node2)
+
+ compiler.find(stub('request', :node => 'node1', :options => {}))
+ compiler.find(stub('node2request', :node => 'node2', :options => {}))
end
- describe "when initializing" do
- before do
- Puppet.expects(:version).returns(1)
- Facter.expects(:value).with('fqdn').returns("my.server.com")
- Facter.expects(:value).with('ipaddress').returns("my.ip.address")
- end
-
- it "should gather data about itself" do
- Puppet::Resource::Catalog::Compiler.new
- end
-
- it "should cache the server metadata and reuse it" do
- compiler = Puppet::Resource::Catalog::Compiler.new
- node1 = stub 'node1', :merge => nil
- node2 = stub 'node2', :merge => nil
- compiler.stubs(:compile)
- Puppet::Node.stubs(:find).with('node1').returns(node1)
- Puppet::Node.stubs(:find).with('node2').returns(node2)
-
- compiler.find(stub('request', :node => 'node1', :options => {}))
- compiler.find(stub('node2request', :node => 'node2', :options => {}))
- end
-
- it "should provide a method for determining if the catalog is networked" do
- compiler = Puppet::Resource::Catalog::Compiler.new
- compiler.should respond_to(:networked?)
- end
-
- describe "and storeconfigs is enabled" do
- before do
- Puppet.settings.expects(:value).with(:storeconfigs).returns true
- end
-
- it "should initialize Rails if it is available" do
- Puppet.features.expects(:rails?).returns true
- Puppet::Rails.expects(:init)
- Puppet::Resource::Catalog::Compiler.new
- end
-
- it "should fail if Rails is unavailable" do
- Puppet.features.expects(:rails?).returns false
- Puppet::Rails.expects(:init).never
- lambda { Puppet::Resource::Catalog::Compiler.new }.should raise_error(Puppet::Error)
- end
- end
+ it "should provide a method for determining if the catalog is networked" do
+ compiler = Puppet::Resource::Catalog::Compiler.new
+ compiler.should respond_to(:networked?)
end
- describe "when finding catalogs" do
- before do
- Facter.stubs(:value).returns("whatever")
-
- @compiler = Puppet::Resource::Catalog::Compiler.new
- @name = "me"
- @node = Puppet::Node.new @name
- @node.stubs(:merge)
- Puppet::Node.stubs(:find).returns @node
- @request = stub 'request', :key => "does not matter", :node => @name, :options => {}
- end
-
- it "should directly use provided nodes" do
- Puppet::Node.expects(:find).never
- @compiler.expects(:compile).with(@node)
- @request.stubs(:options).returns(:use_node => @node)
- @compiler.find(@request)
- end
-
- it "should use the request's node name if no explicit node is provided" do
- Puppet::Node.expects(:find).with(@name).returns(@node)
- @compiler.expects(:compile).with(@node)
- @compiler.find(@request)
- end
-
- it "should use the provided node name if no explicit node is provided and no authenticated node information is available" do
- @request.expects(:node).returns nil
- @request.expects(:key).returns "my_node"
-
- Puppet::Node.expects(:find).with("my_node").returns @node
- @compiler.expects(:compile).with(@node)
- @compiler.find(@request)
- end
-
- it "should fail if no node is passed and none can be found" do
- Puppet::Node.stubs(:find).with(@name).returns(nil)
- proc { @compiler.find(@request) }.should raise_error(ArgumentError)
- end
-
- it "should fail intelligently when searching for a node raises an exception" do
- Puppet::Node.stubs(:find).with(@name).raises "eh"
- proc { @compiler.find(@request) }.should raise_error(Puppet::Error)
- end
-
- it "should pass the found node to the compiler for compiling" do
- Puppet::Node.expects(:find).with(@name).returns(@node)
- config = mock 'config'
- Puppet::Parser::Compiler.expects(:compile).with(@node)
- @compiler.find(@request)
- end
-
- it "should extract and save any facts from the request" do
- Puppet::Node.expects(:find).with(@name).returns @node
- @compiler.expects(:extract_facts_from_request).with(@request)
- Puppet::Parser::Compiler.stubs(:compile)
- @compiler.find(@request)
- end
-
- it "should return the results of compiling as the catalog" do
- Puppet::Node.stubs(:find).returns(@node)
- config = mock 'config'
- result = mock 'result'
-
- Puppet::Parser::Compiler.expects(:compile).returns result
- @compiler.find(@request).should equal(result)
- end
-
- it "should benchmark the compile process" do
- Puppet::Node.stubs(:find).returns(@node)
- @compiler.stubs(:networked?).returns(true)
- @compiler.expects(:benchmark).with do |level, message|
- level == :notice and message =~ /^Compiled catalog/
- end
- Puppet::Parser::Compiler.stubs(:compile)
- @compiler.find(@request)
- end
+ describe "and storeconfigs is enabled" do
+ before do
+ Puppet.settings.expects(:value).with(:storeconfigs).returns true
+ end
+
+ it "should initialize Rails if it is available" do
+ Puppet.features.expects(:rails?).returns true
+ Puppet::Rails.expects(:init)
+ Puppet::Resource::Catalog::Compiler.new
+ end
+
+ it "should fail if Rails is unavailable" do
+ Puppet.features.expects(:rails?).returns false
+ Puppet::Rails.expects(:init).never
+ lambda { Puppet::Resource::Catalog::Compiler.new }.should raise_error(Puppet::Error)
+ end
end
+ end
- describe "when extracting facts from the request" do
- before do
- Facter.stubs(:value).returns "something"
- @compiler = Puppet::Resource::Catalog::Compiler.new
- @request = stub 'request', :options => {}
+ describe "when finding catalogs" do
+ before do
+ Facter.stubs(:value).returns("whatever")
+
+ @compiler = Puppet::Resource::Catalog::Compiler.new
+ @name = "me"
+ @node = Puppet::Node.new @name
+ @node.stubs(:merge)
+ Puppet::Node.stubs(:find).returns @node
+ @request = stub 'request', :key => "does not matter", :node => @name, :options => {}
+ end
- @facts = stub 'facts', :save => nil
- end
+ it "should directly use provided nodes" do
+ Puppet::Node.expects(:find).never
+ @compiler.expects(:compile).with(@node)
+ @request.stubs(:options).returns(:use_node => @node)
+ @compiler.find(@request)
+ end
- it "should do nothing if no facts are provided" do
- Puppet::Node::Facts.expects(:convert_from).never
- @request.options[:facts] = nil
+ it "should use the request's node name if no explicit node is provided" do
+ Puppet::Node.expects(:find).with(@name).returns(@node)
+ @compiler.expects(:compile).with(@node)
+ @compiler.find(@request)
+ end
- @compiler.extract_facts_from_request(@request)
- end
+ it "should use the provided node name if no explicit node is provided and no authenticated node information is available" do
+ @request.expects(:node).returns nil
+ @request.expects(:key).returns "my_node"
- it "should use the Facts class to deserialize the provided facts" do
- @request.options[:facts_format] = "foo"
- @request.options[:facts] = "bar"
- Puppet::Node::Facts.expects(:convert_from).returns @facts
+ Puppet::Node.expects(:find).with("my_node").returns @node
+ @compiler.expects(:compile).with(@node)
+ @compiler.find(@request)
+ end
- @compiler.extract_facts_from_request(@request)
- end
+ it "should fail if no node is passed and none can be found" do
+ Puppet::Node.stubs(:find).with(@name).returns(nil)
+ proc { @compiler.find(@request) }.should raise_error(ArgumentError)
+ end
- it "should use the provided fact format" do
- @request.options[:facts_format] = "foo"
- @request.options[:facts] = "bar"
- Puppet::Node::Facts.expects(:convert_from).with { |format, text| format == "foo" }.returns @facts
+ it "should fail intelligently when searching for a node raises an exception" do
+ Puppet::Node.stubs(:find).with(@name).raises "eh"
+ proc { @compiler.find(@request) }.should raise_error(Puppet::Error)
+ end
- @compiler.extract_facts_from_request(@request)
- end
+ it "should pass the found node to the compiler for compiling" do
+ Puppet::Node.expects(:find).with(@name).returns(@node)
+ config = mock 'config'
+ Puppet::Parser::Compiler.expects(:compile).with(@node)
+ @compiler.find(@request)
+ end
- it "should convert the facts into a fact instance and save it" do
- @request.options[:facts_format] = "foo"
- @request.options[:facts] = "bar"
- Puppet::Node::Facts.expects(:convert_from).returns @facts
+ it "should extract and save any facts from the request" do
+ Puppet::Node.expects(:find).with(@name).returns @node
+ @compiler.expects(:extract_facts_from_request).with(@request)
+ Puppet::Parser::Compiler.stubs(:compile)
+ @compiler.find(@request)
+ end
- @facts.expects(:save)
+ it "should return the results of compiling as the catalog" do
+ Puppet::Node.stubs(:find).returns(@node)
+ config = mock 'config'
+ result = mock 'result'
- @compiler.extract_facts_from_request(@request)
- end
+ Puppet::Parser::Compiler.expects(:compile).returns result
+ @compiler.find(@request).should equal(result)
end
- describe "when finding nodes" do
- before do
- Facter.stubs(:value).returns("whatever")
- @compiler = Puppet::Resource::Catalog::Compiler.new
- @name = "me"
- @node = mock 'node'
- @request = stub 'request', :node => @name, :options => {}
- @compiler.stubs(:compile)
- end
-
- it "should look node information up via the Node class with the provided key" do
- @node.stubs :merge
- Puppet::Node.expects(:find).with(@name).returns(@node)
- @compiler.find(@request)
- end
+ it "should benchmark the compile process" do
+ Puppet::Node.stubs(:find).returns(@node)
+ @compiler.stubs(:networked?).returns(true)
+ @compiler.expects(:benchmark).with do |level, message|
+ level == :notice and message =~ /^Compiled catalog/
+ end
+ Puppet::Parser::Compiler.stubs(:compile)
+ @compiler.find(@request)
end
+ end
- describe "after finding nodes" do
- before do
- Puppet.expects(:version).returns(1)
- Facter.expects(:value).with('fqdn').returns("my.server.com")
- Facter.expects(:value).with('ipaddress').returns("my.ip.address")
- @compiler = Puppet::Resource::Catalog::Compiler.new
- @name = "me"
- @node = mock 'node'
- @request = stub 'request', :node => @name, :options => {}
- @compiler.stubs(:compile)
- Puppet::Node.stubs(:find).with(@name).returns(@node)
- end
-
- it "should add the server's Puppet version to the node's parameters as 'serverversion'" do
- @node.expects(:merge).with { |args| args["serverversion"] == "1" }
- @compiler.find(@request)
- end
-
- it "should add the server's fqdn to the node's parameters as 'servername'" do
- @node.expects(:merge).with { |args| args["servername"] == "my.server.com" }
- @compiler.find(@request)
- end
-
- it "should add the server's IP address to the node's parameters as 'serverip'" do
- @node.expects(:merge).with { |args| args["serverip"] == "my.ip.address" }
- @compiler.find(@request)
- end
+ describe "when extracting facts from the request" do
+ before do
+ Facter.stubs(:value).returns "something"
+ @compiler = Puppet::Resource::Catalog::Compiler.new
+ @request = stub 'request', :options => {}
+
+ @facts = stub 'facts', :save => nil
end
- describe "when filtering resources" do
- before :each do
- Facter.stubs(:value)
- @compiler = Puppet::Resource::Catalog::Compiler.new
- @catalog = stub_everything 'catalog'
- @catalog.stubs(:respond_to?).with(:filter).returns(true)
- end
+ it "should do nothing if no facts are provided" do
+ Puppet::Node::Facts.expects(:convert_from).never
+ @request.options[:facts] = nil
+
+ @compiler.extract_facts_from_request(@request)
+ end
- it "should delegate to the catalog instance filtering" do
- @catalog.expects(:filter)
- @compiler.filter(@catalog)
- end
+ it "should use the Facts class to deserialize the provided facts" do
+ @request.options[:facts_format] = "foo"
+ @request.options[:facts] = "bar"
+ Puppet::Node::Facts.expects(:convert_from).returns @facts
- it "should filter out virtual resources" do
- resource = mock 'resource', :virtual? => true
- @catalog.stubs(:filter).yields(resource)
+ @compiler.extract_facts_from_request(@request)
+ end
- @compiler.filter(@catalog)
- end
+ it "should use the provided fact format" do
+ @request.options[:facts_format] = "foo"
+ @request.options[:facts] = "bar"
+ Puppet::Node::Facts.expects(:convert_from).with { |format, text| format == "foo" }.returns @facts
- it "should return the same catalog if it doesn't support filtering" do
- @catalog.stubs(:respond_to?).with(:filter).returns(false)
+ @compiler.extract_facts_from_request(@request)
+ end
- @compiler.filter(@catalog).should == @catalog
- end
+ it "should convert the facts into a fact instance and save it" do
+ @request.options[:facts_format] = "foo"
+ @request.options[:facts] = "bar"
+ Puppet::Node::Facts.expects(:convert_from).returns @facts
- it "should return the filtered catalog" do
- catalog = stub 'filtered catalog'
- @catalog.stubs(:filter).returns(catalog)
+ @facts.expects(:save)
- @compiler.filter(@catalog).should == catalog
- end
+ @compiler.extract_facts_from_request(@request)
+ end
+ end
+ describe "when finding nodes" do
+ before do
+ Facter.stubs(:value).returns("whatever")
+ @compiler = Puppet::Resource::Catalog::Compiler.new
+ @name = "me"
+ @node = mock 'node'
+ @request = stub 'request', :node => @name, :options => {}
+ @compiler.stubs(:compile)
end
+
+ it "should look node information up via the Node class with the provided key" do
+ @node.stubs :merge
+ Puppet::Node.expects(:find).with(@name).returns(@node)
+ @compiler.find(@request)
+ end
+ end
+
+ describe "after finding nodes" do
+ before do
+ Puppet.expects(:version).returns(1)
+ Facter.expects(:value).with('fqdn').returns("my.server.com")
+ Facter.expects(:value).with('ipaddress').returns("my.ip.address")
+ @compiler = Puppet::Resource::Catalog::Compiler.new
+ @name = "me"
+ @node = mock 'node'
+ @request = stub 'request', :node => @name, :options => {}
+ @compiler.stubs(:compile)
+ Puppet::Node.stubs(:find).with(@name).returns(@node)
+ end
+
+ it "should add the server's Puppet version to the node's parameters as 'serverversion'" do
+ @node.expects(:merge).with { |args| args["serverversion"] == "1" }
+ @compiler.find(@request)
+ end
+
+ it "should add the server's fqdn to the node's parameters as 'servername'" do
+ @node.expects(:merge).with { |args| args["servername"] == "my.server.com" }
+ @compiler.find(@request)
+ end
+
+ it "should add the server's IP address to the node's parameters as 'serverip'" do
+ @node.expects(:merge).with { |args| args["serverip"] == "my.ip.address" }
+ @compiler.find(@request)
+ end
+ end
+
+ describe "when filtering resources" do
+ before :each do
+ Facter.stubs(:value)
+ @compiler = Puppet::Resource::Catalog::Compiler.new
+ @catalog = stub_everything 'catalog'
+ @catalog.stubs(:respond_to?).with(:filter).returns(true)
+ end
+
+ it "should delegate to the catalog instance filtering" do
+ @catalog.expects(:filter)
+ @compiler.filter(@catalog)
+ end
+
+ it "should filter out virtual resources" do
+ resource = mock 'resource', :virtual? => true
+ @catalog.stubs(:filter).yields(resource)
+
+ @compiler.filter(@catalog)
+ end
+
+ it "should return the same catalog if it doesn't support filtering" do
+ @catalog.stubs(:respond_to?).with(:filter).returns(false)
+
+ @compiler.filter(@catalog).should == @catalog
+ end
+
+ it "should return the filtered catalog" do
+ catalog = stub 'filtered catalog'
+ @catalog.stubs(:filter).returns(catalog)
+
+ @compiler.filter(@catalog).should == catalog
+ end
+
+ end
end
diff --git a/spec/unit/indirector/catalog/queue_spec.rb b/spec/unit/indirector/catalog/queue_spec.rb
index 66a30c0d6..38d40c94a 100755
--- a/spec/unit/indirector/catalog/queue_spec.rb
+++ b/spec/unit/indirector/catalog/queue_spec.rb
@@ -5,16 +5,16 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
require 'puppet/indirector/catalog/queue'
describe Puppet::Resource::Catalog::Queue do
- it 'should be a subclass of the Queue terminus' do
- Puppet::Resource::Catalog::Queue.superclass.should equal(Puppet::Indirector::Queue)
- end
+ it 'should be a subclass of the Queue terminus' do
+ Puppet::Resource::Catalog::Queue.superclass.should equal(Puppet::Indirector::Queue)
+ end
- it 'should be registered with the catalog store indirection' do
- indirection = Puppet::Indirector::Indirection.instance(:catalog)
- Puppet::Resource::Catalog::Queue.indirection.should equal(indirection)
- end
+ it 'should be registered with the catalog store indirection' do
+ indirection = Puppet::Indirector::Indirection.instance(:catalog)
+ Puppet::Resource::Catalog::Queue.indirection.should equal(indirection)
+ end
- it 'shall be dubbed ":queue"' do
- Puppet::Resource::Catalog::Queue.name.should == :queue
- end
+ it 'shall be dubbed ":queue"' do
+ Puppet::Resource::Catalog::Queue.name.should == :queue
+ end
end
diff --git a/spec/unit/indirector/catalog/rest_spec.rb b/spec/unit/indirector/catalog/rest_spec.rb
index 909e0a89e..d61054e16 100755
--- a/spec/unit/indirector/catalog/rest_spec.rb
+++ b/spec/unit/indirector/catalog/rest_spec.rb
@@ -5,7 +5,7 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
require 'puppet/indirector/catalog/rest'
describe Puppet::Resource::Catalog::Rest do
- it "should be a sublcass of Puppet::Indirector::REST" do
- Puppet::Resource::Catalog::Rest.superclass.should equal(Puppet::Indirector::REST)
- end
+ it "should be a sublcass of Puppet::Indirector::REST" do
+ Puppet::Resource::Catalog::Rest.superclass.should equal(Puppet::Indirector::REST)
+ end
end
diff --git a/spec/unit/indirector/catalog/yaml_spec.rb b/spec/unit/indirector/catalog/yaml_spec.rb
index 5f233c91c..5a30b8268 100755
--- a/spec/unit/indirector/catalog/yaml_spec.rb
+++ b/spec/unit/indirector/catalog/yaml_spec.rb
@@ -6,20 +6,20 @@ require 'puppet/resource/catalog'
require 'puppet/indirector/catalog/yaml'
describe Puppet::Resource::Catalog::Yaml do
- it "should be a subclass of the Yaml terminus" do
- Puppet::Resource::Catalog::Yaml.superclass.should equal(Puppet::Indirector::Yaml)
- end
+ it "should be a subclass of the Yaml terminus" do
+ Puppet::Resource::Catalog::Yaml.superclass.should equal(Puppet::Indirector::Yaml)
+ end
- it "should have documentation" do
- Puppet::Resource::Catalog::Yaml.doc.should_not be_nil
- end
+ it "should have documentation" do
+ Puppet::Resource::Catalog::Yaml.doc.should_not be_nil
+ end
- it "should be registered with the catalog store indirection" do
- indirection = Puppet::Indirector::Indirection.instance(:catalog)
- Puppet::Resource::Catalog::Yaml.indirection.should equal(indirection)
- end
+ it "should be registered with the catalog store indirection" do
+ indirection = Puppet::Indirector::Indirection.instance(:catalog)
+ Puppet::Resource::Catalog::Yaml.indirection.should equal(indirection)
+ end
- it "should have its name set to :yaml" do
- Puppet::Resource::Catalog::Yaml.name.should == :yaml
- end
+ it "should have its name set to :yaml" do
+ Puppet::Resource::Catalog::Yaml.name.should == :yaml
+ end
end