about summary refs log tree commit homepage
path: root/test/test_http_reader.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/test_http_reader.rb')
-rw-r--r--test/test_http_reader.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/test_http_reader.rb b/test/test_http_reader.rb
new file mode 100644
index 0000000..634b28c
--- /dev/null
+++ b/test/test_http_reader.rb
@@ -0,0 +1,33 @@
+# -*- encoding: binary -*-
+require "./test/setup"
+
+class TestHTTPReader < Test::Unit::TestCase
+  def rsock
+    host = "127.0.0.1"
+    s = TCPServer.new(host, 0)
+    th = Thread.new do
+      c = s.accept
+      c.readpartial(0x666)
+      c.write("HTTP/1.0 200 OK\r\nContent-Length: 666\r\n\r\n666")
+      c.close
+    end
+    path = "http://#{host}:#{s.addr[1]}/"
+    r = MogileFS::HTTPReader.try(path, 666, nil)
+    assert_kind_of IO, r
+    r
+    ensure
+      s.close
+  end
+
+  def test_short_to_s
+    r = rsock
+    assert_raises(MogileFS::SizeMismatchError) { r.to_s }
+    r.close
+  end
+
+  def test_short_stream_to
+    r = rsock
+    assert_raises(MogileFS::SizeMismatchError) { r.stream_to("/dev/null") }
+    r.close
+  end
+end