[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, experimental, updated. debian/2.6.8-1-844-g7ec39d5

Luke Kanies luke at puppetlabs.com
Tue May 10 08:12:14 UTC 2011


The following commit has been merged in the experimental branch:
commit 50756588baad21d9b399051153274a89857433ef
Author: Luke Kanies <luke at puppetlabs.com>
Date:   Sat Apr 9 15:15:52 2011 -0700

    Fixing Indirector::Facts::Couch loading
    
    It was previously failing to load at all if couch was missing,
    but now it only fails on initialization.
    
    This means that you can tell that the terminus is there when
    you're missing couch, but you just can't use it.
    
    Signed-off-by: Luke Kanies <luke at puppetlabs.com>
    Reviewed-by: Daniel Pittman <daniel at puppetlabs.com>

diff --git a/lib/puppet/indirector/couch.rb b/lib/puppet/indirector/couch.rb
index fae934f..243d33d 100644
--- a/lib/puppet/indirector/couch.rb
+++ b/lib/puppet/indirector/couch.rb
@@ -1,6 +1,3 @@
-raise "Couch terminus not supported without couchrest gem" unless Puppet.features.couchdb?
-
-require 'couchrest'
 class Puppet::Indirector::Couch < Puppet::Indirector::Terminus
 
   # The CouchRest database instance. One database instance per Puppet runtime
@@ -13,6 +10,11 @@ class Puppet::Indirector::Couch < Puppet::Indirector::Terminus
     attributes_of get(request)
   end
 
+  def initialize(*args)
+    raise "Couch terminus not supported without couchrest gem" unless Puppet.features.couchdb?
+    super
+  end
+
   # Create or update the couchdb document with the request's data hash.
   #
   def save(request)
diff --git a/spec/unit/indirector/facts/couch_spec.rb b/spec/unit/indirector/facts/couch_spec.rb
index 1de2f7d..3ac0852 100755
--- a/spec/unit/indirector/facts/couch_spec.rb
+++ b/spec/unit/indirector/facts/couch_spec.rb
@@ -3,95 +3,101 @@
 require 'spec_helper'
 
 require 'puppet/node/facts'
+require 'puppet/indirector/facts/couch'
 
-describe "Puppet::Node::Facts::Couch", :if => Puppet.features.couchdb? do
-  require 'puppet/indirector/facts/couch' if Puppet.features.couchdb?
-
-  before do
-    @mock_db = mock('couch db')
-    mock_document = CouchRest::Document.new(:_id => fake_request.key, :facts => fake_request.values)
-    mock_document.stubs(:database).returns(@mock_db)
-    @mock_db.stubs(:get).with(fake_request.key).returns(mock_document)
-    Puppet::Node::Facts::Couch.stubs(:db).returns(@mock_db)
+describe "Puppet::Node::Facts::Couch" do
+  describe "when couchdb is not available", :unless => Puppet.features.couchdb? do
+    it "should fail to initialize" do
+      lambda { Puppet::Node::Facts::Couch.new }.should raise_error
+    end
   end
 
-  subject { Puppet::Node::Facts::Couch }
-
-  describe "#find" do
-    describe "when the node document exists" do
-      it "should find the request by key" do
-        @mock_db.expects(:get).with(fake_request.key).returns({'_id' => fake_request.key, 'facts' => fake_request.instance.values})
-        subject.new.find(fake_request).should == fake_request.instance
-      end
+  describe "when couchdb is available", :if => Puppet.features.couchdb? do
+    before do
+      @mock_db = mock('couch db')
+      mock_document = CouchRest::Document.new(:_id => fake_request.key, :facts => fake_request.values)
+      mock_document.stubs(:database).returns(@mock_db)
+      @mock_db.stubs(:get).with(fake_request.key).returns(mock_document)
+      Puppet::Node::Facts::Couch.stubs(:db).returns(@mock_db)
     end
 
-    describe "when the node document does not exist" do
-      before do
-        @mock_db.expects(:get).
-          with(fake_request.key).
-          raises(RestClient::ResourceNotFound)
-      end
+    subject { Puppet::Node::Facts::Couch }
 
-      it "should return nil" do
-        subject.new.find(fake_request).should be_nil
+    describe "#find" do
+      describe "when the node document exists" do
+        it "should find the request by key" do
+          @mock_db.expects(:get).with(fake_request.key).returns({'_id' => fake_request.key, 'facts' => fake_request.instance.values})
+          subject.new.find(fake_request).should == fake_request.instance
+        end
       end
 
-      it "should send Puppet a debug message" do
-        Puppet.expects(:debug).with("No couchdb document with id: test.local")
-        subject.new.find(fake_request).should be_nil
-      end
+      describe "when the node document does not exist" do
+        before do
+          @mock_db.expects(:get).
+            with(fake_request.key).
+            raises(RestClient::ResourceNotFound)
+        end
 
-    end
-  end
+        it "should return nil" do
+          subject.new.find(fake_request).should be_nil
+        end
 
-  describe "#save" do
-    describe "with options" do
-      subject do
-        lambda { Puppet::Node::Facts::Couch.new.save(fake_request([1])) }
-      end
+        it "should send Puppet a debug message" do
+          Puppet.expects(:debug).with("No couchdb document with id: test.local")
+          subject.new.find(fake_request).should be_nil
+        end
 
-      it { should raise_error(ArgumentError, "PUT does not accept options") }
+      end
     end
 
-    it "should save the json to the CouchDB database" do
-      @mock_db.expects(:save_doc).at_least_once.returns({'ok' => true })
-      subject.new.save(fake_request)
-    end
+    describe "#save" do
+      describe "with options" do
+        subject do
+          lambda { Puppet::Node::Facts::Couch.new.save(fake_request([1])) }
+        end
 
-    describe "when the document exists" do
-      before do
-        @doc = CouchRest::Document.new(:_id => fake_request.key, :facts => fake_request.instance.values)
-        @mock_db.expects(:get).with(fake_request.key).returns(@doc)
+        it { should raise_error(ArgumentError, "PUT does not accept options") }
       end
 
-      it "saves the document" do
-        @doc.expects(:save)
+      it "should save the json to the CouchDB database" do
+        @mock_db.expects(:save_doc).at_least_once.returns({'ok' => true })
         subject.new.save(fake_request)
       end
 
-    end
+      describe "when the document exists" do
+        before do
+          @doc = CouchRest::Document.new(:_id => fake_request.key, :facts => fake_request.instance.values)
+          @mock_db.expects(:get).with(fake_request.key).returns(@doc)
+        end
+
+        it "saves the document" do
+          @doc.expects(:save)
+          subject.new.save(fake_request)
+        end
 
-    describe "when the document does not exist" do
-      before do
-        @mock_db.expects(:get).
-          with(fake_request.key).
-          raises(RestClient::ResourceNotFound)
       end
 
-      it "saves the document" do
-        @mock_db.expects(:save_doc)
-        subject.new.save(fake_request)
+      describe "when the document does not exist" do
+        before do
+          @mock_db.expects(:get).
+            with(fake_request.key).
+            raises(RestClient::ResourceNotFound)
+        end
+
+        it "saves the document" do
+          @mock_db.expects(:save_doc)
+          subject.new.save(fake_request)
+        end
+
       end
 
     end
 
+    def fake_request(options={})
+      facts = YAML.load_file(File.join(PuppetSpec::FIXTURE_DIR, 'yaml', 'test.local.yaml'))
+      Struct.new(:instance, :key, :options).new(facts, facts.name, options)
+    end
+    private :fake_request
   end
-
-  def fake_request(options={})
-    facts = YAML.load_file(File.join(PuppetSpec::FIXTURE_DIR, 'yaml', 'test.local.yaml'))
-    Struct.new(:instance, :key, :options).new(facts, facts.name, options)
-  end
-  private :fake_request
-
 end
 

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list