Ruby mogilefs-client 3.12.2
[ruby-mogilefs-client.git] / test / test_mogilefs_integration_list_keys.rb
blob6f56548d4ed97f91fd3e8dd71ee4c62109322b64
1 # -*- encoding: binary -*-
2 require './test/fresh'
4 class TestMogileFSIntegrationListKeys < Test::Unit::TestCase
5   include TestFreshSetup
7   def setup
8     setup_mogilefs
9     add_host_device_domain
10     @client = MogileFS::MogileFS.new(:hosts => @trackers, :domain => @domain)
11   end
13   alias teardown teardown_mogilefs
15   def test_list_keys
16     k = %w(a b c d e f g)
17     k.each { |x| @client.store_content("lk_#{x}", nil, x) }
18     expect = k.map { |x| "lk_#{x}" }
19     rv = @client.list_keys
20     assert_equal([ expect, expect.last ] , rv)
21     nr = 0
22     @client.list_keys do |key, length, devcount|
23       assert_equal 1, length
24       assert_kind_of Integer, devcount
25       assert_equal expect[nr], key
26       nr += 1
27     end
28   end
30   def test_list_keys_strange
31     @client.store_content("hello+world", nil, "HI")
32     rv = @client.list_keys
33     assert_equal "hello+world", rv[0][0]
34   end
36   def test_each_key
37     9.times { |i| @client.store_content("ek_#{i}", nil, i.to_s) }
38     n = 0
39     @client.each_key do |key|
40       assert_equal "ek_#{n.to_s}", key
41       n += 1
42     end
43     assert_equal 9, n
44   end
46   def test_each_file_info
47     9.times { |i| @client.store_content("ek_#{i}", nil, i.to_s) }
48     n = 0
49     @client.each_file_info do |info|
50       assert_equal @client.domain, info["domain"]
51       assert_equal n.to_s.size, info["length"]
52       assert_kind_of Integer, info["fid"]
53       assert_kind_of Integer, info["devcount"]
54       assert_equal "default", info["class"]
55       assert_equal "ek_#{n}", info["key"]
56       n += 1
57     end
58     assert_equal 9, n
59   end
60 end