1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
| | # -*- encoding: binary -*-
require './test/setup'
class TestMogileFS__DbBackend < Test::Unit::TestCase
def setup
@my = FakeMysql.new
@mgmy = MogileFS::Mysql.new(:mysql => @my)
@mg = MogileFS::MogileFS.new(:db_backend => @mgmy, :domain => 'test')
end
def test_initialize
assert_equal 'test', @mg.domain
assert @mg.readonly?
end
def test_list_keys_block
expect_full = [ [ 'foo', 123, 2 ], [ 'bar', 456, 1 ] ]
expect_keys = [ [ 'foo', 'bar' ], 'bar' ]
@my.expect << expect_full
full = []
keys = @mg.list_keys('test') do |dkey,length,devcount|
full << [ dkey, length, devcount ]
end
assert_equal expect_keys, keys
assert_equal expect_full, full
end
def test_list_keys
expect_full = [ [ 'foo', 123, 2 ], [ 'bar', 456, 1 ] ]
expect_keys = [ [ 'foo', 'bar' ], 'bar' ]
@my.expect << expect_full
keys = @mg.list_keys('test')
assert_equal expect_keys, keys
end
def test_size
@my.expect << [ [ '123' ] ]
assert_equal 123, @mg.size('foo')
@my.expect << [ [ '456' ] ]
assert_equal 456, @mg.size('foo')
end
def test_store_file_readonly
assert_raises(MogileFS::ReadOnlyError) do
@mg.store_file 'new_key', 'test', '/dev/null'
end
end
def test_store_content_readonly
assert_raises(MogileFS::ReadOnlyError) do
@mg.store_content 'new_key', 'test', 'data'
end
end
def test_new_file_readonly
assert_raises(MogileFS::ReadOnlyError) { @mg.new_file 'new_key', 'test' }
end
def test_rename_readonly
assert_raises(MogileFS::ReadOnlyError) { @mg.rename 'a', 'b' }
end
def test_delete_readonly
assert_raises(MogileFS::ReadOnlyError) { @mg.delete 'no_such_key' }
end
def test_sleep
assert_nothing_raised { assert_equal({}, @mg.sleep(1)) }
end
end
|