client: small speedup for list_keys_verbose
[ruby-mogilefs-client.git] / test / test_http_reader.rb
blobf6f00557185a8603d7254b30e634d6a381f6ea91
1 # -*- encoding: binary -*-
2 require "./test/setup"
4 class TestHTTPReader < Test::Unit::TestCase
5   def rsock
6     host = "127.0.0.1"
7     s = TCPServer.new(host, 0)
8     th = Thread.new do
9       c = s.accept
10       c.readpartial(0x666)
11       c.write("HTTP/1.0 200 OK\r\nContent-Length: 666\r\n\r\n666")
12       c.close
13     end
14     path = "http://#{host}:#{s.addr[1]}/"
15     r = MogileFS::HTTPReader.try(path, 666, nil)
16     assert_nil th.value
17     assert_kind_of IO, r
18     r
19     ensure
20       s.close
21   end
23   def test_short_to_s
24     r = rsock
25     assert_raises(MogileFS::SizeMismatchError) { r.to_s }
26     r.close
27   end
29   def test_short_stream_to
30     r = rsock
31     assert_raises(MogileFS::SizeMismatchError) { r.stream_to("/dev/null") }
32     r.close
33   end
34 end