tests: retry random ports correctly
[ruby-mogilefs-client.git] / test / test_client.rb
blob802ee1d77290051cebfe3cd34e60792f8f3d476e
1 require 'test/unit'
2 require 'mogilefs'
4 class MogileFS::Backend
5   attr_accessor :timeout, :lasterr, :lasterrstr, :hosts
6 end
8 class MogileFS::Client
9   attr_accessor :hosts
10 end
12 class TestClient < Test::Unit::TestCase
14   def setup
15     @client = MogileFS::Client.new :hosts => ['kaa:6001']
16   end
18   def test_initialize
19     client = MogileFS::Client.new :hosts => ['kaa:6001']
20     assert_not_nil client
21     assert_instance_of MogileFS::Backend, client.backend
22     assert_equal ['kaa:6001'], client.hosts
24     client = MogileFS::Client.new :hosts => ['kaa:6001'], :timeout => 5
25     assert_equal 5, client.backend.timeout
26   end
28   def test_err
29     @client.backend.lasterr = 'you'
30     assert_equal 'you', @client.err
31   end
33   def test_errstr
34     @client.backend.lasterrstr = 'totally suck'
35     assert_equal 'totally suck', @client.errstr
36   end
38   def test_reload
39     orig_backend = @client.backend
41     @client.hosts = ['ziz:6001']
42     @client.reload
44     assert_not_same @client.backend, orig_backend
45     assert_equal ['ziz:6001'], @client.backend.hosts
46   end
48   def test_readonly_eh_readonly
49     client = MogileFS::Client.new :hosts => ['kaa:6001'], :readonly => true
50     assert_equal true, client.readonly?
51   end
53   def test_readonly_eh_readwrite
54     assert_equal false, @client.readonly?
55   end
57 end