Branching mogilefs-client to version 1.2.1
[ruby-mogilefs-client.git] / test / test_admin.rb
blob9227cfe780fd90d71372eb028c3495cdb388f373
1 require 'test/setup'
3 class TestMogileFS__Admin < TestMogileFS
5   def setup
6     @klass = MogileFS::Admin
7     super
8   end
10   def test_clean
11     res = {"host1_remoteroot"=>"/mnt/mogilefs/rur-1",
12            "host1_hostname"=>"rur-1",
13            "host1_hostid"=>"1",
14            "host1_http_get_port"=>"",
15            "host1_altip"=>"",
16            "hosts"=>"1",
17            "host1_hostip"=>"",
18            "host1_http_port"=>"",
19            "host1_status"=>"alive",
20            "host1_altmask"=>""}
21     actual = @client.clean 'hosts', 'host', res
22   
23     expected = [{"status"=>"alive",
24                  "http_get_port"=>"",
25                  "http_port"=>"",
26                  "hostid"=>"1",
27                  "hostip"=>"",
28                  "hostname"=>"rur-1",
29                  "remoteroot"=>"/mnt/mogilefs/rur-1",
30                  "altip"=>"",
31                  "altmask"=>""}]
33     assert_equal expected, actual
34   end
36   def test_each_fid
37     @backend.stats = {
38       'fidmax' => '182',
39       'fidcount' => '2',
40     }
42     @backend.list_fids = {
43       'fid_count' => '1',
44       'fid_1_fid' => '99',
45       'fid_1_class' => 'normal',
46       'fid_1_devcount' => '2',
47       'fid_1_domain' => 'test',
48       'fid_1_key' => 'file_key',
49       'fid_1_length' => '4',
50     }
52     @backend.list_fids = {
53       'fid_count' => '1',
54       'fid_1_fid' => '182',
55       'fid_1_class' => 'normal',
56       'fid_1_devcount' => '2',
57       'fid_1_domain' => 'test',
58       'fid_1_key' => 'new_new_key',
59       'fid_1_length' => '9',
60     }
62     fids = []
63     @client.each_fid { |fid| fids << fid }
65     expected = [
66       { "fid"      => "99",
67         "class"    => "normal",
68         "domain"   => "test",
69         "devcount" => "2",
70         "length"   => "4",
71         "key"      => "file_key" },
72       { "fid"      => "182",
73         "class"    => "normal",
74         "devcount" => "2",
75         "domain"   => "test",
76         "length"   => "9",
77         "key"      => "new_new_key" },
78     ]
80     assert_equal expected, fids
81   end
83   def test_get_domains
84     @backend.get_domains = {
85       'domains' => 2,
86       'domain1' => 'test',
87       'domain2' => 'images',
88       'domain1classes' => '1',
89       'domain2classes' => '2',
90       'domain1class1name' => 'default',
91       'domain1class1mindevcount' => '2',
92       'domain2class1name' => 'default',
93       'domain2class1mindevcount' => '2',
94       'domain2class2name' => 'resize',
95       'domain2class2mindevcount' => '1',
96     }
98     expected = {
99       'test'   => { 'default' => 2, },
100       'images' => { 'default' => 2, 'resize' => 1 },
101     }
103     assert_equal expected, @client.get_domains
104   end
106   def disabled_test_get_stats
107     @backend.stats = {}
109     expected = {
110       'fids' => { 'max' => '99', 'count' => '2' },
111       'device' => [
112         { 'status' => 'alive', 'files' => '2', 'id' => '1', 'host' => 'rur-1' },
113         { 'status' => 'alive', 'files' => '2', 'id' => '2', 'host' => 'rur-2' }
114       ],
115       'replication' => [
116         { 'files' => '2', 'class' => 'normal', 'devcount' => '2',
117           'domain' => 'test' }
118       ],
119       'file' => [{ 'files' => '2', 'class' => 'normal', 'domain' => 'test' }]
120     }
122     assert_equal 
123   end
125   def test_get_stats_fids
126     @backend.stats = {
127       'fidmax' => 99,
128       'fidcount' => 2,
129     }
131     expected = {
132       'fids' => { 'max' => 99, 'count' => 2 },
133     }
135     assert_equal expected, @client.get_stats('all')
136   end
138   def test_list_fids
139     @backend.list_fids = {
140       'fid_count' => '2',
141       'fid_1_fid' => '99',
142       'fid_1_class' => 'normal',
143       'fid_1_devcount' => '2',
144       'fid_1_domain' => 'test',
145       'fid_1_key' => 'file_key',
146       'fid_1_length' => '4',
147       'fid_2_fid' => '82',
148       'fid_2_class' => 'normal',
149       'fid_2_devcount' => '2',
150       'fid_2_domain' => 'test',
151       'fid_2_key' => 'new_new_key',
152       'fid_2_length' => '9',
153     }
155     expected = [
156       { "fid"      => "99",
157         "class"    => "normal",
158         "domain"   => "test",
159         "devcount" => "2",
160         "length"   => "4",
161         "key"      => "file_key" },
162       { "fid"      => "82",
163         "class"    => "normal",
164         "devcount" => "2",
165         "domain"   => "test",
166         "length"   => "9",
167         "key"      => "new_new_key" },
168     ]
170     assert_equal expected, @client.list_fids(0, 100)
171   end