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