summaryrefslogtreecommitdiffstats
path: root/spec/unit/network/http/rack
diff options
context:
space:
mode:
authorBrice Figureau <brice-puppet@daysofwonder.com>2010-04-10 16:30:03 +0200
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commitee5d7f196fa62046f8fc3d3d723da608b17ce531 (patch)
treeaa92df8067b573167034d62e08c6dbe4c0d35b47 /spec/unit/network/http/rack
parent63c122f397c915cb1bec1a645958c808da92dce4 (diff)
downloadpuppet-ee5d7f196fa62046f8fc3d3d723da608b17ce531.tar.gz
puppet-ee5d7f196fa62046f8fc3d3d723da608b17ce531.tar.xz
puppet-ee5d7f196fa62046f8fc3d3d723da608b17ce531.zip
Add master side file content streaming
This patch allows the puppetmaster to serve file chunks by chunks without ever reading the file content in RAM. This allows serving large files directly with the master without impacting the master memory footprint. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
Diffstat (limited to 'spec/unit/network/http/rack')
-rwxr-xr-xspec/unit/network/http/rack/rest.rb50
1 files changed, 50 insertions, 0 deletions
diff --git a/spec/unit/network/http/rack/rest.rb b/spec/unit/network/http/rack/rest.rb
index e916712f3..75642f9f7 100755
--- a/spec/unit/network/http/rack/rest.rb
+++ b/spec/unit/network/http/rack/rest.rb
@@ -74,6 +74,26 @@ describe "Puppet::Network::HTTP::RackREST" do
@handler.set_response(@response, "mybody", 400)
end
+
+ describe "when result is a File" do
+ before :each do
+ stat = stub 'stat', :size => 100
+ @file = stub 'file', :stat => stat, :path => "/tmp/path"
+ @file.stubs(:is_a?).with(File).returns(true)
+ end
+
+ it "should set the Content-Length header" do
+ @response.expects(:[]=).with("Content-Length", 100)
+
+ @handler.set_response(@response, @file, 200)
+ end
+
+ it "should return a RackFile adapter as body" do
+ @response.expects(:body=).with { |val| val.is_a?(Puppet::Network::HTTP::RackREST::RackFile) }
+
+ @handler.set_response(@response, @file, 200)
+ end
+ end
end
describe "and determining the request parameters" do
@@ -197,3 +217,33 @@ describe "Puppet::Network::HTTP::RackREST" do
end
end
end
+
+describe Puppet::Network::HTTP::RackREST::RackFile do
+ before(:each) do
+ stat = stub 'stat', :size => 100
+ @file = stub 'file', :stat => stat, :path => "/tmp/path"
+ @rackfile = Puppet::Network::HTTP::RackREST::RackFile.new(@file)
+ end
+
+ it "should have an each method" do
+ @rackfile.should be_respond_to(:each)
+ end
+
+ it "should yield file chunks by chunks" do
+ @file.expects(:read).times(3).with(8192).returns("1", "2", nil)
+ i = 1
+ @rackfile.each do |chunk|
+ chunk.to_i.should == i
+ i += 1
+ end
+ end
+
+ it "should have a close method" do
+ @rackfile.should be_respond_to(:close)
+ end
+
+ it "should delegate close to File close" do
+ @file.expects(:close)
+ @rackfile.close
+ end
+end \ No newline at end of file