ensure get_file_data users notice truncated responses
[ruby-mogilefs-client.git] / test / test_http_reader.rb
blob634b28c61b6ad9fa51fd5bcf109a2964fcdda9f8
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_kind_of IO, r
17     r
18     ensure
19       s.close
20   end
22   def test_short_to_s
23     r = rsock
24     assert_raises(MogileFS::SizeMismatchError) { r.to_s }
25     r.close
26   end
28   def test_short_stream_to
29     r = rsock
30     assert_raises(MogileFS::SizeMismatchError) { r.stream_to("/dev/null") }
31     r.close
32   end
33 end