"new_file" gets many options for Content-MD5 handling
[ruby-mogilefs-client.git] / test / test_admin.rb
blobba247230d9882f0d032187f484ad968cd5487368
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.list_fids = {
39       'fid_count' => '1',
40       'fid_1_fid' => '99',
41       'fid_1_class' => 'normal',
42       'fid_1_devcount' => '2',
43       'fid_1_domain' => 'test',
44       'fid_1_key' => 'file_key',
45       'fid_1_length' => '4',
46     }
48     @backend.list_fids = {
49       'fid_count' => '1',
50       'fid_1_fid' => '182',
51       'fid_1_class' => 'normal',
52       'fid_1_devcount' => '2',
53       'fid_1_domain' => 'test',
54       'fid_1_key' => 'new_new_key',
55       'fid_1_length' => '9',
56     }
57     @backend.list_fids = { 'fid_count' => 0 }
59     fids = []
60     @client.each_fid { |fid| fids << fid }
62     expected = [
63       { "fid"      => 99,
64         "class"    => "normal",
65         "domain"   => "test",
66         "devcount" => 2,
67         "length"   => 4,
68         "key"      => "file_key" },
69       { "fid"      => 182,
70         "class"    => "normal",
71         "devcount" => 2,
72         "domain"   => "test",
73         "length"   => 9,
74         "key"      => "new_new_key" },
75     ]
77     assert_equal expected, fids
78   end
80   def test_get_domains
81     @backend.get_domains = {
82       'domains' => 2,
83       'domain1' => 'test',
84       'domain2' => 'images',
85       'domain1classes' => '1',
86       'domain2classes' => '2',
87       'domain1class1name' => 'default',
88       'domain1class1mindevcount' => '2',
89       'domain2class1name' => 'default',
90       'domain2class1mindevcount' => '2',
91       'domain2class2name' => 'resize',
92       'domain2class2mindevcount' => '1',
93     }
95     expected = {
96       'test'   => { 'default' => 2, },
97       'images' => { 'default' => 2, 'resize' => 1 },
98     }
100     assert_equal expected, @client.get_domains
101   end
103   def test_get_stats_fids
104     @backend.stats = {
105       'fidmax' => 99,
106       'fidcount' => 2,
107     }
109     expected = {
110       'fids' => { 'max' => 99, 'count' => 2 },
111     }
113     assert_equal expected, @client.get_stats('all')
114   end
116   def test_list_fids
117     @backend.list_fids = {
118       'fid_count' => '2',
119       'fid_1_fid' => '99',
120       'fid_1_class' => 'normal',
121       'fid_1_devcount' => '2',
122       'fid_1_domain' => 'test',
123       'fid_1_key' => 'file_key',
124       'fid_1_length' => '4',
125       'fid_2_fid' => '82',
126       'fid_2_class' => 'normal',
127       'fid_2_devcount' => '2',
128       'fid_2_domain' => 'test',
129       'fid_2_key' => 'new_new_key',
130       'fid_2_length' => '9',
131     }
133     expected = [
134       { "fid"      => 99,
135         "class"    => "normal",
136         "domain"   => "test",
137         "devcount" => 2,
138         "length"   => 4,
139         "key"      => "file_key" },
140       { "fid"      => 82,
141         "class"    => "normal",
142         "devcount" => 2,
143         "domain"   => "test",
144         "length"   => 9,
145         "key"      => "new_new_key" },
146     ]
148     assert_equal expected, @client.list_fids(0, 100)
149   end