summaryrefslogtreecommitdiffstats
path: root/spec/unit/network
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-09-23 23:50:43 -0500
committerLuke Kanies <luke@madstop.com>2008-09-23 23:50:43 -0500
commitbb23861e334e617b544c11bc75a35c40b36185a2 (patch)
tree18da91858e4fded78a56d673fc69014fdf266676 /spec/unit/network
parente31df2f7f5e98c524b68cd724cfaa3e308e7b9a1 (diff)
parentac5db5ec115455e54090542870847820357739a2 (diff)
downloadpuppet-bb23861e334e617b544c11bc75a35c40b36185a2.tar.gz
puppet-bb23861e334e617b544c11bc75a35c40b36185a2.tar.xz
puppet-bb23861e334e617b544c11bc75a35c40b36185a2.zip
Merge branch 'feature/master/1481'
This merges in the new fileserving code -- we're now using REST to do fileserving, rather than xmlrpc. Conflicts: lib/puppet/parameter.rb lib/puppet/type/file.rb spec/unit/type/file.rb
Diffstat (limited to 'spec/unit/network')
-rwxr-xr-xspec/unit/network/format.rb17
-rwxr-xr-xspec/unit/network/format_handler.rb31
-rwxr-xr-xspec/unit/network/formats.rb30
-rwxr-xr-xspec/unit/network/http/handler.rb31
-rwxr-xr-xspec/unit/network/http/mongrel/rest.rb6
-rwxr-xr-xspec/unit/network/http/webrick/rest.rb6
6 files changed, 106 insertions, 15 deletions
diff --git a/spec/unit/network/format.rb b/spec/unit/network/format.rb
index b960a3f73..244bff306 100755
--- a/spec/unit/network/format.rb
+++ b/spec/unit/network/format.rb
@@ -74,10 +74,27 @@ describe Puppet::Network::Format do
Puppet::Network::Format.new(:yaml).should_not be_supported(String)
end
+ it "should not consider a class supported unless the format is suitable" do
+ @format.expects(:suitable?).returns false
+ @format.should_not be_supported(FormatRenderer)
+ end
+
it "should always downcase mimetypes" do
@format.mime = "Foo/Bar"
@format.mime.should == "foo/bar"
end
+
+ it "should support having a weight" do
+ @format.should respond_to(:weight)
+ end
+
+ it "should default to a weight of of 5" do
+ @format.weight.should == 5
+ end
+
+ it "should be able to override its weight at initialization" do
+ Puppet::Network::Format.new(:foo, :weight => 1).weight.should == 1
+ end
end
describe "when converting between instances and formatted text" do
diff --git a/spec/unit/network/format_handler.rb b/spec/unit/network/format_handler.rb
index 35e996516..3dcff6199 100755
--- a/spec/unit/network/format_handler.rb
+++ b/spec/unit/network/format_handler.rb
@@ -21,18 +21,31 @@ describe Puppet::Network::FormatHandler do
end
it "should include all supported formats" do
- one = stub 'supported', :supported? => true, :name => "one"
- two = stub 'supported', :supported? => false, :name => "two"
- three = stub 'supported', :supported? => true, :name => "three"
- four = stub 'supported', :supported? => false, :name => "four"
- Puppet::Network::FormatHandler.expects(:formats).returns %w{one two three four}
- Puppet::Network::FormatHandler.expects(:format).with("one").returns one
- Puppet::Network::FormatHandler.expects(:format).with("two").returns two
- Puppet::Network::FormatHandler.expects(:format).with("three").returns three
- Puppet::Network::FormatHandler.expects(:format).with("four").returns four
+ one = stub 'supported', :supported? => true, :name => "one", :weight => 1
+ two = stub 'supported', :supported? => false, :name => "two", :weight => 1
+ three = stub 'supported', :supported? => true, :name => "three", :weight => 1
+ four = stub 'supported', :supported? => false, :name => "four", :weight => 1
+ Puppet::Network::FormatHandler.stubs(:formats).returns %w{one two three four}
+ Puppet::Network::FormatHandler.stubs(:format).with("one").returns one
+ Puppet::Network::FormatHandler.stubs(:format).with("two").returns two
+ Puppet::Network::FormatHandler.stubs(:format).with("three").returns three
+ Puppet::Network::FormatHandler.stubs(:format).with("four").returns four
FormatTester.supported_formats.sort.should == %w{one three}.sort
end
+ it "should return the supported formats in decreasing order of weight" do
+ one = stub 'supported', :supported? => true, :name => "one", :weight => 1
+ two = stub 'supported', :supported? => true, :name => "two", :weight => 6
+ three = stub 'supported', :supported? => true, :name => "three", :weight => 2
+ four = stub 'supported', :supported? => true, :name => "four", :weight => 8
+ Puppet::Network::FormatHandler.stubs(:formats).returns %w{one two three four}
+ Puppet::Network::FormatHandler.stubs(:format).with("one").returns one
+ Puppet::Network::FormatHandler.stubs(:format).with("two").returns two
+ Puppet::Network::FormatHandler.stubs(:format).with("three").returns three
+ Puppet::Network::FormatHandler.stubs(:format).with("four").returns four
+ FormatTester.supported_formats.should == %w{four two three one}
+ end
+
it "should return the first format as the default format" do
FormatTester.expects(:supported_formats).returns %w{one two}
FormatTester.default_format.should == "one"
diff --git a/spec/unit/network/formats.rb b/spec/unit/network/formats.rb
index f7493360d..0e21fefa7 100755
--- a/spec/unit/network/formats.rb
+++ b/spec/unit/network/formats.rb
@@ -99,4 +99,34 @@ describe "Puppet Network Format" do
@text.mime.should == "text/plain"
end
end
+
+ describe Puppet::Network::FormatHandler.format(:raw) do
+ before do
+ @format = Puppet::Network::FormatHandler.format(:raw)
+ end
+
+ it "should exist" do
+ @format.should_not be_nil
+ end
+
+ it "should have its mimetype set to application/x-raw" do
+ @format.mime.should == "application/x-raw"
+ end
+
+ it "should always be supported" do
+ @format.should be_supported(String)
+ end
+
+ it "should fail if its multiple_render method is used" do
+ lambda { @format.render_multiple("foo") }.should raise_error(NotImplementedError)
+ end
+
+ it "should fail if its multiple_intern method is used" do
+ lambda { @format.intern_multiple(String, "foo") }.should raise_error(NotImplementedError)
+ end
+
+ it "should have a weight of 1" do
+ @format.weight.should == 1
+ end
+ end
end
diff --git a/spec/unit/network/http/handler.rb b/spec/unit/network/http/handler.rb
index 6fc932091..ed0f25121 100755
--- a/spec/unit/network/http/handler.rb
+++ b/spec/unit/network/http/handler.rb
@@ -224,6 +224,9 @@ describe Puppet::Network::HTTP::Handler do
@handler.stubs(:singular?).returns(true)
@handler.stubs(:request_key).returns('key')
@model_class.stubs(:find).returns @result
+
+ @format = stub 'format', :suitable? => true
+ Puppet::Network::FormatHandler.stubs(:format).returns @format
end
it "should fail to find model if key is not specified" do
@@ -246,6 +249,28 @@ describe Puppet::Network::HTTP::Handler do
@handler.do_find(@request, @response)
end
+ it "should fail if no accept header is provided" do
+ @handler.expects(:accept_header).with(@request).returns nil
+ lambda { @handler.do_find(@request, @response) }.should raise_error(ArgumentError)
+ end
+
+ it "should fail if the accept header does not contain a valid format" do
+ @handler.expects(:accept_header).with(@request).returns ""
+ lambda { @handler.do_find(@request, @response) }.should raise_error(RuntimeError)
+ end
+
+ it "should not use an unsuitable format" do
+ @handler.expects(:accept_header).with(@request).returns "foo,bar"
+ foo = mock 'foo', :suitable? => false
+ bar = mock 'bar', :suitable? => true
+ Puppet::Network::FormatHandler.expects(:format).with("foo").returns foo
+ Puppet::Network::FormatHandler.expects(:format).with("bar").returns bar
+
+ @handler.expects(:set_content_type).with(@response, "bar") # the suitable one
+
+ @handler.do_find(@request, @response)
+ end
+
it "should render the result using the first format specified in the accept header" do
@handler.expects(:accept_header).with(@request).returns "one,two"
@result.expects(:render).with("one")
@@ -298,6 +323,9 @@ describe Puppet::Network::HTTP::Handler do
@result = [@result1, @result2]
@model_class.stubs(:render_multiple).returns "my rendered instances"
@model_class.stubs(:search).returns(@result)
+
+ @format = stub 'format', :suitable? => true
+ Puppet::Network::FormatHandler.stubs(:format).returns @format
end
it "should use a common method for determining the request parameters" do
@@ -409,6 +437,9 @@ describe Puppet::Network::HTTP::Handler do
@model_instance = stub('indirected model instance', :save => true)
@model_class.stubs(:convert_from).returns(@model_instance)
+
+ @format = stub 'format', :suitable? => true
+ Puppet::Network::FormatHandler.stubs(:format).returns @format
end
it "should use the 'body' hook to retrieve the body of the request" do
diff --git a/spec/unit/network/http/mongrel/rest.rb b/spec/unit/network/http/mongrel/rest.rb
index 3b248dcfe..9dbc1c9ab 100755
--- a/spec/unit/network/http/mongrel/rest.rb
+++ b/spec/unit/network/http/mongrel/rest.rb
@@ -53,9 +53,9 @@ describe "Puppet::Network::HTTP::MongrelREST" do
@handler.path(@request).should == "/foo"
end
- it "should use the second part of the request path as the request key" do
- @params.expects(:[]).with(Mongrel::Const::REQUEST_PATH).returns "/foo/bar"
- @handler.request_key(@request).should == "bar"
+ it "should use the remainder of the request path as the request key" do
+ @params.expects(:[]).with(Mongrel::Const::REQUEST_PATH).returns "/foo/bar/baz"
+ @handler.request_key(@request).should == "bar/baz"
end
it "should return nil as the request key if no second field is present" do
diff --git a/spec/unit/network/http/webrick/rest.rb b/spec/unit/network/http/webrick/rest.rb
index 620201472..1f4ccbe29 100755
--- a/spec/unit/network/http/webrick/rest.rb
+++ b/spec/unit/network/http/webrick/rest.rb
@@ -47,9 +47,9 @@ describe Puppet::Network::HTTP::WEBrickREST do
@handler.path(@request).should == "/foo"
end
- it "should return the second field in the path as the request key" do
- @request.expects(:path).returns "/foo/bar"
- @handler.request_key(@request).should == "bar"
+ it "should return the remainder of the path as the request key" do
+ @request.expects(:path).returns "/foo/bar/baz"
+ @handler.request_key(@request).should == "bar/baz"
end
it "should return nil as the request key if there is no second field" do