1 # -*- encoding: binary -*-
4 class TestMogileFS__DbBackend < Test::Unit::TestCase
7 @mgmy = MogileFS::Mysql.new(:mysql => @my)
8 @mg = MogileFS::MogileFS.new(:db_backend => @mgmy, :domain => 'test')
12 assert_equal 'test', @mg.domain
16 def test_list_keys_block
17 expect_full = [ [ 'foo', 123, 2 ], [ 'bar', 456, 1 ] ]
18 expect_keys = [ [ 'foo', 'bar' ], 'bar' ]
19 @my.expect << expect_full
21 keys = @mg.list_keys('test') do |dkey,length,devcount|
22 full << [ dkey, length, devcount ]
24 assert_equal expect_keys, keys
25 assert_equal expect_full, full
29 expect_full = [ [ 'foo', 123, 2 ], [ 'bar', 456, 1 ] ]
30 expect_keys = [ [ 'foo', 'bar' ], 'bar' ]
31 @my.expect << expect_full
32 keys = @mg.list_keys('test')
33 assert_equal expect_keys, keys
37 @my.expect << [ [ '123' ] ]
38 assert_equal 123, @mg.size('foo')
40 @my.expect << [ [ '456' ] ]
41 assert_equal 456, @mg.size('foo')
44 def test_store_file_readonly
45 assert_raises(MogileFS::ReadOnlyError) do
46 @mg.store_file 'new_key', 'test', '/dev/null'
50 def test_store_content_readonly
51 assert_raises(MogileFS::ReadOnlyError) do
52 @mg.store_content 'new_key', 'test', 'data'
56 def test_new_file_readonly
57 assert_raises(MogileFS::ReadOnlyError) { @mg.new_file 'new_key', 'test' }
60 def test_rename_readonly
61 assert_raises(MogileFS::ReadOnlyError) { @mg.rename 'a', 'b' }
64 def test_delete_readonly
65 assert_raises(MogileFS::ReadOnlyError) { @mg.delete 'no_such_key' }
69 assert_equal({}, @mg.sleep(1))