summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-07-30 23:19:08 -0500
committerLuke Kanies <luke@madstop.com>2008-07-30 23:19:08 -0500
commitc2c8941de5973137d631c1f90f7c07e54cc89e3d (patch)
tree1a7ab7d4242ca47b7c851d4a7463a23771c439d1 /spec
parent186f3cd34fb7fa3bc1ff683a5178444526259f92 (diff)
downloadpuppet-c2c8941de5973137d631c1f90f7c07e54cc89e3d.tar.gz
puppet-c2c8941de5973137d631c1f90f7c07e54cc89e3d.tar.xz
puppet-c2c8941de5973137d631c1f90f7c07e54cc89e3d.zip
Correctly handling when REST searches return nothing.
We return a 404, which the client can correctly handle. That wasn't the actual problem causing failing tests, of course -- the problem was that one side of our stub was autodetecting marshal, and the other side was forcing yaml, which strangely didn't work. It was only happening with searching, though, not finding et al. The 'search returning nil' problem was a bit of a red herring but needed to be fixed, too. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'spec')
-rwxr-xr-xspec/integration/indirector/rest.rb9
-rwxr-xr-xspec/unit/indirector/rest.rb6
-rwxr-xr-xspec/unit/network/http/handler.rb14
3 files changed, 28 insertions, 1 deletions
diff --git a/spec/integration/indirector/rest.rb b/spec/integration/indirector/rest.rb
index 86d4d4291..b307e3cab 100755
--- a/spec/integration/indirector/rest.rb
+++ b/spec/integration/indirector/rest.rb
@@ -138,6 +138,9 @@ describe Puppet::Indirector::REST do
@model_instances = [ Puppet::TestIndirectedFoo.new(23), Puppet::TestIndirectedFoo.new(24) ]
@mock_model.stubs(:search).returns @model_instances
+ # Force yaml, because otherwise our mocks can't work correctly
+ Puppet::TestIndirectedFoo.stubs(:supported_formats).returns %w{yaml}
+
@mock_model.stubs(:render_multiple).returns @model_instances.to_yaml
end
@@ -354,6 +357,10 @@ describe Puppet::Indirector::REST do
describe "when matching model instances can be found" do
before :each do
@model_instances = [ Puppet::TestIndirectedFoo.new(23), Puppet::TestIndirectedFoo.new(24) ]
+
+ # Force yaml, because otherwise our mocks can't work correctly
+ Puppet::TestIndirectedFoo.stubs(:supported_formats).returns %w{yaml}
+
@mock_model.stubs(:search).returns @model_instances
@mock_model.stubs(:render_multiple).returns @model_instances.to_yaml
end
@@ -390,7 +397,7 @@ describe Puppet::Indirector::REST do
end
it "should return nil" do
- Puppet::TestIndirectedFoo.search('bar').should be_nil
+ Puppet::TestIndirectedFoo.search('bar').should == []
end
end
diff --git a/spec/unit/indirector/rest.rb b/spec/unit/indirector/rest.rb
index 801e8888e..28ceb693a 100755
--- a/spec/unit/indirector/rest.rb
+++ b/spec/unit/indirector/rest.rb
@@ -187,6 +187,12 @@ describe Puppet::Indirector::REST do
@searcher.search(@request)
end
+ it "should return an empty array if serialization returns nil" do
+ @model.stubs(:convert_from_multiple).returns nil
+
+ @searcher.search(@request).should == []
+ end
+
it "should generate an error when result data deserializes fails" do
@searcher.expects(:deserialize).raises(ArgumentError)
lambda { @searcher.search(@request) }.should raise_error(ArgumentError)
diff --git a/spec/unit/network/http/handler.rb b/spec/unit/network/http/handler.rb
index 1ed816d97..816c0ea2e 100755
--- a/spec/unit/network/http/handler.rb
+++ b/spec/unit/network/http/handler.rb
@@ -330,6 +330,20 @@ describe Puppet::Network::HTTP::Handler do
@handler.expects(:set_response).with { |response, data| data == "my rendered instances" }
@handler.do_search(@request, @response)
end
+
+ it "should return a 404 when searching returns an empty array" do
+ @model_class.stubs(:name).returns "my name"
+ @handler.expects(:set_response).with { |response, body, status| status == 404 }
+ @model_class.stubs(:search).returns([])
+ @handler.do_search(@request, @response)
+ end
+
+ it "should return a 404 when searching returns nil" do
+ @model_class.stubs(:name).returns "my name"
+ @handler.expects(:set_response).with { |response, body, status| status == 404 }
+ @model_class.stubs(:search).returns([])
+ @handler.do_search(@request, @response)
+ end
end
describe "when destroying a model instance" do