added failing test: reading chunks from an empty (zero-length) grid-stored file

This commit is contained in:
Daniël van de Burgt 2011-05-10 22:57:22 -05:00
parent b8ab13e7f9
commit 3cb1e4644b
2 changed files with 38 additions and 0 deletions

0
test/data/empty_data Normal file
View File

View File

@ -13,6 +13,7 @@ def read_and_write_stream(filename, read_length, opts={})
read_data = "" read_data = ""
while(chunk = file.read(read_length)) while(chunk = file.read(read_length))
read_data << chunk read_data << chunk
break if chunk.empty?
end end
assert_equal data.length, read_data.length assert_equal data.length, read_data.length
end end
@ -195,6 +196,39 @@ class GridTest < Test::Unit::TestCase
end end
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 || {} context "Streaming: " do || {}
setup do setup do
@grid = Grid.new(@db, 'test-fs') @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) read_and_write_stream('small_data.txt', 1, :chunk_size => 2)
end 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 should "put and get a small io object" do
read_and_write_stream('small_data.txt', 1) read_and_write_stream('small_data.txt', 1)
end end