summaryrefslogtreecommitdiffstats
path: root/spec/unit/agent.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-01-23 18:49:26 -0600
committerLuke Kanies <luke@madstop.com>2009-02-06 18:08:42 -0600
commitd53ad3181d3f5953b00512d7793945d238d1879f (patch)
treef23104eada8d7baa2b82238124755ca90ebd8a78 /spec/unit/agent.rb
parentf38277fb7d044394665db369892c01162b866863 (diff)
downloadpuppet-d53ad3181d3f5953b00512d7793945d238d1879f.tar.gz
puppet-d53ad3181d3f5953b00512d7793945d238d1879f.tar.xz
puppet-d53ad3181d3f5953b00512d7793945d238d1879f.zip
Converting the catalog as needed
Converting to a Resource catalog for transmission, then converting to a RAL catalog on the client. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'spec/unit/agent.rb')
-rwxr-xr-xspec/unit/agent.rb74
1 files changed, 49 insertions, 25 deletions
diff --git a/spec/unit/agent.rb b/spec/unit/agent.rb
index e0ae3689e..0d6ed952e 100755
--- a/spec/unit/agent.rb
+++ b/spec/unit/agent.rb
@@ -123,10 +123,12 @@ describe Puppet::Agent, "when retrieving a catalog" do
@agent = Puppet::Agent.new
@catalog = Puppet::Resource::Catalog.new
+
+ @agent.stubs(:convert_catalog).returns @catalog
end
it "should use the Catalog class to get its catalog" do
- Puppet::Resource::Catalog.expects(:get).returns @catalog
+ Puppet::Resource::Catalog.expects(:find).returns @catalog
@agent.retrieve_catalog
end
@@ -134,68 +136,90 @@ describe Puppet::Agent, "when retrieving a catalog" do
it "should use its Facter name to retrieve the catalog" do
Facter.stubs(:value).returns "eh"
Facter.expects(:value).with("hostname").returns "myhost"
- Puppet::Resource::Catalog.expects(:get).with { |name, options| name == "myhost" }.returns @catalog
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| name == "myhost" }.returns @catalog
@agent.retrieve_catalog
end
it "should default to returning a catalog retrieved directly from the server, skipping the cache" do
- Puppet::Resource::Catalog.expects(:get).with { |name, options| options[:use_cache] == false }.returns @catalog
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:use_cache] == false }.returns @catalog
@agent.retrieve_catalog.should == @catalog
end
it "should return the cached catalog when no catalog can be retrieved from the server" do
- Puppet::Resource::Catalog.expects(:get).with { |name, options| options[:use_cache] == false }.returns nil
- Puppet::Resource::Catalog.expects(:get).with { |name, options| options[:use_cache] == true }.returns @catalog
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:use_cache] == false }.returns nil
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:use_cache] == true }.returns @catalog
+
+ @agent.retrieve_catalog.should == @catalog
+ end
+
+ it "should not look in the cache for a catalog if one is returned from the server" do
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:use_cache] == false }.returns @catalog
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:use_cache] == true }.never
@agent.retrieve_catalog.should == @catalog
end
it "should return the cached catalog when retrieving the remote catalog throws an exception" do
- Puppet::Resource::Catalog.expects(:get).with { |name, options| options[:use_cache] == false }.raises "eh"
- Puppet::Resource::Catalog.expects(:get).with { |name, options| options[:use_cache] == true }.returns @catalog
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:use_cache] == false }.raises "eh"
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:use_cache] == true }.returns @catalog
@agent.retrieve_catalog.should == @catalog
end
it "should return nil if no cached catalog is available and no catalog can be retrieved from the server" do
- Puppet::Resource::Catalog.expects(:get).with { |name, options| options[:use_cache] == false }.returns nil
- Puppet::Resource::Catalog.expects(:get).with { |name, options| options[:use_cache] == true }.returns nil
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:use_cache] == false }.returns nil
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:use_cache] == true }.returns nil
@agent.retrieve_catalog.should be_nil
end
- it "should record the retrieval time with the catalog" do
- @agent.expects(:thinmark).yields.then.returns 10
+ it "should convert the catalog before returning" do
+ Puppet::Resource::Catalog.stubs(:find).returns @catalog
- Puppet::Resource::Catalog.expects(:get).returns @catalog
+ @agent.expects(:convert_catalog).with { |cat, dur| cat == @catalog }.returns "converted catalog"
+ @agent.retrieve_catalog.should == "converted catalog"
+ end
- @catalog.expects(:retrieval_duration=).with 10
+ it "should return nil if there is an error while retrieving the catalog" do
+ Puppet::Resource::Catalog.expects(:find).raises "eh"
- @agent.retrieve_catalog
+ @agent.retrieve_catalog.should be_nil
end
+end
- it "should write the catalog's class file" do
- @catalog.expects(:write_class_file)
+describe Puppet::Agent, "when converting the catalog" do
+ before do
+ Puppet.settings.stubs(:use).returns(true)
+ @agent = Puppet::Agent.new
- Puppet::Resource::Catalog.expects(:get).returns @catalog
+ @catalog = Puppet::Resource::Catalog.new
+ @oldcatalog = stub 'old_catalog', :to_ral => @catalog
+ end
- @agent.retrieve_catalog
+ it "should convert the catalog to a RAL-formed catalog" do
+ @oldcatalog.expects(:to_ral).returns @catalog
+
+ @agent.convert_catalog(@oldcatalog, 10).should equal(@catalog)
end
- it "should mark the catalog as a host catalog" do
- @catalog.expects(:host_config=).with true
+ it "should record the passed retrieval time with the RAL catalog" do
+ @catalog.expects(:retrieval_duration=).with 10
- Puppet::Resource::Catalog.expects(:get).returns @catalog
+ @agent.convert_catalog(@oldcatalog, 10)
+ end
- @agent.retrieve_catalog
+ it "should write the RAL catalog's class file" do
+ @catalog.expects(:write_class_file)
+
+ @agent.convert_catalog(@oldcatalog, 10)
end
- it "should return nil if there is an error while retrieving the catalog" do
- Puppet::Resource::Catalog.expects(:get).raises "eh"
+ it "should mark the RAL catalog as a host catalog" do
+ @catalog.expects(:host_config=).with true
- @agent.retrieve_catalog.should be_nil
+ @agent.convert_catalog(@oldcatalog, 10)
end
end