Ruby mogilefs-client 3.12.2
[ruby-mogilefs-client.git] / test / test_client.rb
blobcbf298affcc0917794f1a58e275f0709c368816f
1 # -*- encoding: binary -*-
2 require 'test/unit'
3 require 'mogilefs'
5 class MogileFS::Backend
6   attr_accessor :timeout, :hosts
7   attr_writer :lasterr, :lasterrstr
8 end
10 class MogileFS::Client
11   attr_accessor :hosts
12 end
14 class TestClient < Test::Unit::TestCase
16   def setup
17     @client = MogileFS::Client.new :hosts => ['kaa:6001']
18   end
20   def test_initialize
21     client = MogileFS::Client.new :hosts => ['kaa:6001']
22     assert_not_nil client
23     assert_instance_of MogileFS::Backend, client.backend
24     assert_equal ['kaa:6001'], client.hosts
26     client = MogileFS::Client.new :hosts => ['kaa:6001'], :timeout => 5
27     assert_equal 5, client.backend.timeout
28   end
30   def test_err
31     @client.backend.lasterr = 'you'
32     assert_equal 'you', @client.err
33   end
35   def test_errstr
36     @client.backend.lasterrstr = 'totally suck'
37     assert_equal 'totally suck', @client.errstr
38   end
40   def test_reload
41     orig_backend = @client.backend
43     @client.hosts = ['ziz:6001']
44     @client.reload
46     assert_not_same @client.backend, orig_backend
47     assert_equal ['ziz:6001'], @client.backend.hosts
48   end
50   def test_readonly_eh_readonly
51     client = MogileFS::Client.new :hosts => ['kaa:6001'], :readonly => true
52     assert_equal true, client.readonly?
53   end
55   def test_readonly_eh_readwrite
56     assert_equal false, @client.readonly?
57   end
59 end