Ruby mogilefs-client 3.4.0
[ruby-mogilefs-client.git] / test / test_client.rb
bloba6e6c1f66074a8d6f0b20c64b1124e0fe66314bd
1 # -*- encoding: binary -*-
2 require 'test/unit'
3 require 'mogilefs'
5 class MogileFS::Backend
6   attr_accessor :timeout, :lasterr, :lasterrstr, :hosts
7 end
9 class MogileFS::Client
10   attr_accessor :hosts
11 end
13 class TestClient < Test::Unit::TestCase
15   def setup
16     @client = MogileFS::Client.new :hosts => ['kaa:6001']
17   end
19   def test_initialize
20     client = MogileFS::Client.new :hosts => ['kaa:6001']
21     assert_not_nil client
22     assert_instance_of MogileFS::Backend, client.backend
23     assert_equal ['kaa:6001'], client.hosts
25     client = MogileFS::Client.new :hosts => ['kaa:6001'], :timeout => 5
26     assert_equal 5, client.backend.timeout
27   end
29   def test_err
30     @client.backend.lasterr = 'you'
31     assert_equal 'you', @client.err
32   end
34   def test_errstr
35     @client.backend.lasterrstr = 'totally suck'
36     assert_equal 'totally suck', @client.errstr
37   end
39   def test_reload
40     orig_backend = @client.backend
42     @client.hosts = ['ziz:6001']
43     @client.reload
45     assert_not_same @client.backend, orig_backend
46     assert_equal ['ziz:6001'], @client.backend.hosts
47   end
49   def test_readonly_eh_readonly
50     client = MogileFS::Client.new :hosts => ['kaa:6001'], :readonly => true
51     assert_equal true, client.readonly?
52   end
54   def test_readonly_eh_readwrite
55     assert_equal false, @client.readonly?
56   end
58 end