Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added failing test: reading chunks from an empty (zero-length) grid-s…

…tored file
  • Loading branch information...
commit 3cb1e4644b6703ee0064233bae9ad940d85063ac 1 parent b8ab13e
Daniël van de Burgt authored
Showing with 38 additions and 0 deletions.
  1. 0  test/data/empty_data
  2. +38 −0 test/grid_test.rb
View
0  test/data/empty_data
No changes.
View
38 test/grid_test.rb
@@ -13,6 +13,7 @@ def read_and_write_stream(filename, read_length, opts={})
read_data = ""
while(chunk = file.read(read_length))
read_data << chunk
+ break if chunk.empty?
end
assert_equal data.length, read_data.length
end
@@ -195,6 +196,39 @@ class GridTest < Test::Unit::TestCase
end
end
+ context "Grid streaming an empty file: " do
+ setup do
+ @grid = Grid.new(@db, 'test-fs')
+ filename = 'empty_data'
+ @io = File.open(File.join(File.dirname(__FILE__), 'data', filename), 'r')
+ id = @grid.put(@io, :filename => filename)
+ @file = @grid.get(id)
+ @io.rewind
+ @data = @io.read
+ if @data.respond_to?(:force_encoding)
+ @data.force_encoding("binary")
+ end
+ end
+
+ should "be equal in length" do
+ @io.rewind
+ assert_equal @io.read.length, @file.read.length
+ end
+
+ should "read the file" do
+ read_data = ""
+ @file.each do |chunk|
+ read_data << chunk
+ end
+ assert_equal @data.length, read_data.length
+ end
+
+ should "read the file if no block is given" do
+ read_data = @file.each
+ assert_equal @data.length, read_data.length
+ end
+ end
+
context "Streaming: " do || {}
setup do
@grid = Grid.new(@db, 'test-fs')
@@ -204,6 +238,10 @@ class GridTest < Test::Unit::TestCase
read_and_write_stream('small_data.txt', 1, :chunk_size => 2)
end
+ should "put and get an empty io object" do
+ read_and_write_stream('empty_data', 1)
+ end
+
should "put and get a small io object" do
read_and_write_stream('small_data.txt', 1)
end
Please sign in to comment.
Something went wrong with that request. Please try again.