tests: create fresh intances for all integration tests
[ruby-mogilefs-client.git] / test / test_mogilefs_integration_list_keys.rb
blob8492a2af7b2a17fac9a7af96e54d13311d79c51a
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   def test_list_keys
14     k = %w(a b c d e f g)
15     k.each { |x| @client.store_content("lk_#{x}", nil, x) }
16     expect = k.map { |x| "lk_#{x}" }
17     rv = @client.list_keys
18     assert_equal([ expect, expect.last ] , rv)
19     nr = 0
20     @client.list_keys do |key, length, devcount|
21       assert_equal 1, length
22       assert_kind_of Integer, devcount
23       assert_equal expect[nr], key
24       nr += 1
25     end
26   end
28   def test_list_keys_strange
29     @client.store_content("hello+world", nil, "HI")
30     rv = @client.list_keys
31     assert_equal "hello+world", rv[0][0]
32   end
34   def test_each_key
35     9.times { |i| @client.store_content("ek_#{i}", nil, i.to_s) }
36     n = 0
37     @client.each_key do |key|
38       assert_equal "ek_#{n.to_s}", key
39       n += 1
40     end
41     assert_equal 9, n
42   end
44   def test_each_file_info
45     9.times { |i| @client.store_content("ek_#{i}", nil, i.to_s) }
46     n = 0
47     @client.each_file_info do |info|
48       assert_equal @client.domain, info["domain"]
49       assert_equal n.to_s.size, info["length"]
50       assert_kind_of Integer, info["fid"]
51       assert_kind_of Integer, info["devcount"]
52       assert_equal "default", info["class"]
53       assert_equal "ek_#{n}", info["key"]
54       n += 1
55     end
56     assert_equal 9, n
57   end
58 end