diff options
author | Rick Bradley <rick@rickbradley.com> | 2008-04-02 00:48:54 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-04-11 13:10:39 -0500 |
commit | f28f20b675737741a98b1b87b4791f736a996d40 (patch) | |
tree | b67032811412f78980fe0fd0d3efa96964e3df58 /spec | |
parent | 07974401178a8b46314971bc7a9858cff1d9797b (diff) | |
download | puppet-f28f20b675737741a98b1b87b4791f736a996d40.tar.gz puppet-f28f20b675737741a98b1b87b4791f736a996d40.tar.xz puppet-f28f20b675737741a98b1b87b4791f736a996d40.zip |
Added support for destroy/DELETE over REST (including units & integrations on both webrick & mongrel).
Added pending specs for the trivialities in the REST network_fetch and network_delete methods.
Refactored YAML exception detection out into a private helper method.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/integration/indirector/rest.rb | 76 | ||||
-rwxr-xr-x | spec/unit/indirector/rest.rb | 59 |
2 files changed, 130 insertions, 5 deletions
diff --git a/spec/integration/indirector/rest.rb b/spec/integration/indirector/rest.rb index 418575fb6..46a26ee91 100644 --- a/spec/integration/indirector/rest.rb +++ b/spec/integration/indirector/rest.rb @@ -146,7 +146,43 @@ describe Puppet::Indirector::REST do end describe "when destroying a model instance over REST" do - it "needs more specs" + describe "when a matching model instance can be found" do + before :each do + @mock_model = stub('faked model', :destroy => true) + Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:model).returns(@mock_model) + end + + it "should not fail" do + lambda { Puppet::TestIndirectedFoo.destroy('bar') }.should_not raise_error + end + + it 'should return success' do + Puppet::TestIndirectedFoo.destroy('bar').should == true + end + end + + describe "when no matching model instance can be found" do + before :each do + @mock_model = stub('faked model', :destroy => false) + Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:model).returns(@mock_model) + end + + it "should return failure" do + Puppet::TestIndirectedFoo.destroy('bar').should == false + end + end + + describe "when an exception is encountered in destroying a model instance" do + before :each do + @mock_model = stub('faked model') + @mock_model.stubs(:destroy).raises(RuntimeError) + Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:model).returns(@mock_model) + end + + it "should raise an exception" do + lambda { Puppet::TestIndirectedFoo.destroy('bar') }.should raise_error(RuntimeError) + end + end end describe "when saving a model instance over REST" do @@ -281,7 +317,43 @@ describe Puppet::Indirector::REST do end describe "when destroying a model instance over REST" do - it "needs more specs" + describe "when a matching model instance can be found" do + before :each do + @mock_model = stub('faked model', :destroy => true) + Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:model).returns(@mock_model) + end + + it "should not fail" do + lambda { Puppet::TestIndirectedFoo.destroy('bar') }.should_not raise_error + end + + it 'should return success' do + Puppet::TestIndirectedFoo.destroy('bar').should == true + end + end + + describe "when no matching model instance can be found" do + before :each do + @mock_model = stub('faked model', :destroy => false) + Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:model).returns(@mock_model) + end + + it "should return failure" do + Puppet::TestIndirectedFoo.destroy('bar').should == false + end + end + + describe "when an exception is encountered in destroying a model instance" do + before :each do + @mock_model = stub('faked model') + @mock_model.stubs(:destroy).raises(RuntimeError) + Puppet::Network::HTTP::MongrelREST.any_instance.stubs(:model).returns(@mock_model) + end + + it "should raise an exception" do + lambda { Puppet::TestIndirectedFoo.destroy('bar') }.should raise_error(RuntimeError) + end + end end describe "when saving a model instance over REST" do diff --git a/spec/unit/indirector/rest.rb b/spec/unit/indirector/rest.rb index 37c0480ed..fb3790e0c 100755 --- a/spec/unit/indirector/rest.rb +++ b/spec/unit/indirector/rest.rb @@ -19,6 +19,28 @@ describe Puppet::Indirector::REST do @searcher = @rest_class.new end + + describe "when doing a network fetch" do + it "should escape the provided path" + it "should look up the appropriate remote server" + it "should look up the appropriate remote port" + it "should use the GET http method" + it "should use the appropriate remote server" + it "should use the appropriate remote port" + it "should use the escaped provided path" + it "should return the results of the GET request" + end + + describe "when doing a network delete" do + it "should escape the provided path" + it "should look up the appropriate remote server" + it "should look up the appropriate remote port" + it "should use the delete http method" + it "should use the appropriate remote server" + it "should use the appropriate remote port" + it "should use the escaped provided path" + it "should return the results of the DELETE request" + end describe "when doing a find" do before :each do @@ -106,9 +128,40 @@ describe Puppet::Indirector::REST do end describe "when doing a destroy" do - it "should deserialize result data into a boolean" - it "should generate an error when result data deserializes improperly" - it "should generate an error when result data specifies an error" + before :each do + @result = true.to_yaml + @searcher.stubs(:network_delete).returns(@result) # neuter the network connection + @model.stubs(:from_yaml).returns(@instance) + end + + it "should look up the model instance over the network" do + @searcher.expects(:network_delete).returns(@result) + @searcher.destroy('foo') + end + + it "should look up the model instance using the named indirection" do + @searcher.expects(:network_delete).with {|path| path =~ %r{^#{@indirection.name.to_s}/} }.returns(@result) + @searcher.destroy('foo') + end + + it "should look up the model instance using the provided key" do + @searcher.expects(:network_delete).with {|path| path =~ %r{/foo$} }.returns(@result) + @searcher.destroy('foo') + end + + it "should deserialize result data" do + YAML.expects(:load).with(@result) + @searcher.destroy('foo') + end + + it "should return deserialized result data" do + @searcher.destroy('foo').should == true + end + + it "should generate an error when result data specifies an error" do + @searcher.stubs(:network_delete).returns(RuntimeError.new("bogus").to_yaml) + lambda { @searcher.destroy('foo') }.should raise_error(RuntimeError) + end end describe "when doing a save" do |